sites-conformes-posthog 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sites_conformes_posthog-0.1.0/LICENSE +21 -0
- sites_conformes_posthog-0.1.0/PKG-INFO +73 -0
- sites_conformes_posthog-0.1.0/README.md +53 -0
- sites_conformes_posthog-0.1.0/pyproject.toml +35 -0
- sites_conformes_posthog-0.1.0/pyproject.toml.orig +37 -0
- sites_conformes_posthog-0.1.0/src/sites_conformes_posthog/__init__.py +0 -0
- sites_conformes_posthog-0.1.0/src/sites_conformes_posthog/apps.py +8 -0
- sites_conformes_posthog-0.1.0/src/sites_conformes_posthog/templates/sites_conformes_core/base.html +35 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sites-conformes-posthog contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sites-conformes-posthog
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Identify authenticated CMS users to PostHog so team activity can be excluded from insights.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Framework :: Django
|
|
12
|
+
Requires-Dist: django>=5.0
|
|
13
|
+
Requires-Dist: sites-conformes>=4.0
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Project-URL: Homepage, https://github.com/incubateur-ademe/sites-conformes-posthog
|
|
16
|
+
Project-URL: Repository, https://github.com/incubateur-ademe/sites-conformes-posthog
|
|
17
|
+
Project-URL: Changelog, https://github.com/incubateur-ademe/sites-conformes-posthog/blob/main/CHANGELOG.md
|
|
18
|
+
Project-URL: Issues, https://github.com/incubateur-ademe/sites-conformes-posthog/issues
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# sites-conformes-posthog
|
|
22
|
+
|
|
23
|
+
Charge et configure PostHog sur toutes les pages, et identifie les
|
|
24
|
+
utilisateurs connectés au CMS afin de pouvoir exclure l'équipe des insights
|
|
25
|
+
(comme sur [quefairedemesobjets](https://github.com/incubateur-ademe/quefairedemesobjets/blob/main/webapp/static/to_compile/controllers/shared/analytics.ts)).
|
|
26
|
+
|
|
27
|
+
La configuration vit dans le code, pas dans **Réglages → Scripts** : elle
|
|
28
|
+
passe par le proxy nginx du site (`api_host: "/ph"`, voir
|
|
29
|
+
`infra/scalingo-proxy/servers.conf.erb`) et ne doit pas dériver au gré des
|
|
30
|
+
synchronisations de contenu. Ne collez donc **pas** de `posthog.init(...)`
|
|
31
|
+
dans les scripts personnalisés - il ferait doublon.
|
|
32
|
+
|
|
33
|
+
## Réglages
|
|
34
|
+
|
|
35
|
+
- `POSTHOG_KEY` (settings Django, depuis la variable d'environnement du même
|
|
36
|
+
nom) : la clé de projet. Vide = pas de PostHog (dev, tests). En prod elle
|
|
37
|
+
arrive par OpenTofu (`var.posthog_key`, variable GitHub `POSTHOG_KEY`).
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv add sites-conformes-posthog
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Ce package surcharge `sites_conformes_core/base.html` (fourni par
|
|
46
|
+
`sites_conformes`). Il doit être placé **avant** `sites_conformes` dans
|
|
47
|
+
`INSTALLED_APPS` :
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
INSTALLED_APPS = [
|
|
51
|
+
...,
|
|
52
|
+
"sites_conformes_posthog",
|
|
53
|
+
"sites_conformes",
|
|
54
|
+
"sites_conformes.core",
|
|
55
|
+
...,
|
|
56
|
+
]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Deux blocs sont étendus avec `{{ block.super }}` : `tracking` (dans le
|
|
60
|
+
`<head>`, loader + `posthog.init`) et `body_tracking_scripts`
|
|
61
|
+
(`posthog.identify` si `request.user.is_authenticated`).
|
|
62
|
+
|
|
63
|
+
## Configuration côté PostHog
|
|
64
|
+
|
|
65
|
+
Dans **PostHog → Project Settings → Filter out internal and test users**,
|
|
66
|
+
ajouter un filtre pour exclure l'équipe, par exemple :
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
email contains "@beta.gouv.fr"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
ou tout autre critère basé sur `email`/`admin`, les deux propriétés
|
|
73
|
+
envoyées par `posthog.identify()`.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# sites-conformes-posthog
|
|
2
|
+
|
|
3
|
+
Charge et configure PostHog sur toutes les pages, et identifie les
|
|
4
|
+
utilisateurs connectés au CMS afin de pouvoir exclure l'équipe des insights
|
|
5
|
+
(comme sur [quefairedemesobjets](https://github.com/incubateur-ademe/quefairedemesobjets/blob/main/webapp/static/to_compile/controllers/shared/analytics.ts)).
|
|
6
|
+
|
|
7
|
+
La configuration vit dans le code, pas dans **Réglages → Scripts** : elle
|
|
8
|
+
passe par le proxy nginx du site (`api_host: "/ph"`, voir
|
|
9
|
+
`infra/scalingo-proxy/servers.conf.erb`) et ne doit pas dériver au gré des
|
|
10
|
+
synchronisations de contenu. Ne collez donc **pas** de `posthog.init(...)`
|
|
11
|
+
dans les scripts personnalisés - il ferait doublon.
|
|
12
|
+
|
|
13
|
+
## Réglages
|
|
14
|
+
|
|
15
|
+
- `POSTHOG_KEY` (settings Django, depuis la variable d'environnement du même
|
|
16
|
+
nom) : la clé de projet. Vide = pas de PostHog (dev, tests). En prod elle
|
|
17
|
+
arrive par OpenTofu (`var.posthog_key`, variable GitHub `POSTHOG_KEY`).
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add sites-conformes-posthog
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Ce package surcharge `sites_conformes_core/base.html` (fourni par
|
|
26
|
+
`sites_conformes`). Il doit être placé **avant** `sites_conformes` dans
|
|
27
|
+
`INSTALLED_APPS` :
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
INSTALLED_APPS = [
|
|
31
|
+
...,
|
|
32
|
+
"sites_conformes_posthog",
|
|
33
|
+
"sites_conformes",
|
|
34
|
+
"sites_conformes.core",
|
|
35
|
+
...,
|
|
36
|
+
]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Deux blocs sont étendus avec `{{ block.super }}` : `tracking` (dans le
|
|
40
|
+
`<head>`, loader + `posthog.init`) et `body_tracking_scripts`
|
|
41
|
+
(`posthog.identify` si `request.user.is_authenticated`).
|
|
42
|
+
|
|
43
|
+
## Configuration côté PostHog
|
|
44
|
+
|
|
45
|
+
Dans **PostHog → Project Settings → Filter out internal and test users**,
|
|
46
|
+
ajouter un filtre pour exclure l'équipe, par exemple :
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
email contains "@beta.gouv.fr"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
ou tout autre critère basé sur `email`/`admin`, les deux propriétés
|
|
53
|
+
envoyées par `posthog.identify()`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sites-conformes-posthog"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Identify authenticated CMS users to PostHog so team activity can be excluded from insights."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Development Status :: 3 - Alpha",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Framework :: Django",
|
|
14
|
+
]
|
|
15
|
+
requires-python = ">=3.12"
|
|
16
|
+
dependencies = [
|
|
17
|
+
"django>=5.0",
|
|
18
|
+
"sites-conformes>=4.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/incubateur-ademe/sites-conformes-posthog"
|
|
23
|
+
Repository = "https://github.com/incubateur-ademe/sites-conformes-posthog"
|
|
24
|
+
Changelog = "https://github.com/incubateur-ademe/sites-conformes-posthog/blob/main/CHANGELOG.md"
|
|
25
|
+
Issues = "https://github.com/incubateur-ademe/sites-conformes-posthog/issues"
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = ["ruff>=0.15"]
|
|
29
|
+
|
|
30
|
+
[build-system]
|
|
31
|
+
requires = ["uv_build>=0.9,<0.13"]
|
|
32
|
+
build-backend = "uv_build"
|
|
33
|
+
|
|
34
|
+
[tool.uv.build-backend]
|
|
35
|
+
module-name = "sites_conformes_posthog"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sites-conformes-posthog"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Identify authenticated CMS users to PostHog so team activity can be excluded from insights."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Development Status :: 3 - Alpha",
|
|
10
|
+
"Intended Audience :: Developers",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Framework :: Django",
|
|
14
|
+
]
|
|
15
|
+
requires-python = ">=3.12"
|
|
16
|
+
dependencies = [
|
|
17
|
+
"django>=5.0",
|
|
18
|
+
"sites-conformes>=4.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/incubateur-ademe/sites-conformes-posthog"
|
|
23
|
+
Repository = "https://github.com/incubateur-ademe/sites-conformes-posthog"
|
|
24
|
+
Changelog = "https://github.com/incubateur-ademe/sites-conformes-posthog/blob/main/CHANGELOG.md"
|
|
25
|
+
Issues = "https://github.com/incubateur-ademe/sites-conformes-posthog/issues"
|
|
26
|
+
|
|
27
|
+
[dependency-groups]
|
|
28
|
+
dev = [
|
|
29
|
+
"ruff>=0.15",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["uv_build>=0.9,<0.13"]
|
|
34
|
+
build-backend = "uv_build"
|
|
35
|
+
|
|
36
|
+
[tool.uv.build-backend]
|
|
37
|
+
module-name = "sites_conformes_posthog"
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from django.apps import AppConfig
|
|
2
|
+
from django.utils.translation import gettext_lazy as _
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SitesConformesPosthogConfig(AppConfig):
|
|
6
|
+
default_auto_field = "django.db.models.BigAutoField"
|
|
7
|
+
name = "sites_conformes_posthog"
|
|
8
|
+
verbose_name = _("PostHog identification")
|
sites_conformes_posthog-0.1.0/src/sites_conformes_posthog/templates/sites_conformes_core/base.html
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{% extends "sites_conformes_core/base.html" %}
|
|
2
|
+
{% load wagtail_dsfr_tags %}
|
|
3
|
+
|
|
4
|
+
{# PostHog loader + init, in code rather than in Réglages → Scripts: the
|
|
5
|
+
config (first-party /ph proxy path, EU UI host) must not drift with
|
|
6
|
+
content syncs. POSTHOG_KEY empty = no analytics (dev, tests). #}
|
|
7
|
+
{% block tracking %}
|
|
8
|
+
{{ block.super }}
|
|
9
|
+
{% settings_value "POSTHOG_KEY" as posthog_key %}
|
|
10
|
+
{% if posthog_key %}
|
|
11
|
+
<script>
|
|
12
|
+
!function(t,e){var o,n,p,r;e.__SV||(window.posthog && window.posthog.__loaded)||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="Ei Ni init zi Gi Nr Ui Xi Vi capture calculateEventProperties tn register register_once register_for_session unregister unregister_for_session an getFeatureFlag getFeatureFlagPayload getFeatureFlagResult isFeatureEnabled reloadFeatureFlags updateFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys renderSurvey displaySurvey cancelPendingSurvey canRenderSurvey canRenderSurveyAsync ln identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset setIdentity clearIdentity get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException addExceptionStep captureLog startExceptionAutocapture stopExceptionAutocapture loadToolbar get_property getSessionProperty nn Qi createPersonProfile setInternalOrTestUser sn qi cn opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing get_explicit_consent_status is_capturing clear_opt_in_out_capturing Ji debug Fr rn getPageViewId captureTraceFeedback captureTraceMetric Bi".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
|
|
13
|
+
posthog.init("{{ posthog_key|escapejs }}", {
|
|
14
|
+
api_host: "/ph",
|
|
15
|
+
ui_host: "https://eu.posthog.com",
|
|
16
|
+
defaults: "2026-01-30",
|
|
17
|
+
person_profiles: "identified_only",
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
{% endif %}
|
|
21
|
+
{% endblock tracking %}
|
|
22
|
+
|
|
23
|
+
{% block body_tracking_scripts %}
|
|
24
|
+
{{ block.super }}
|
|
25
|
+
{% if request.user.is_authenticated %}
|
|
26
|
+
<script>
|
|
27
|
+
if (window.posthog) {
|
|
28
|
+
posthog.identify("{{ request.user.username|escapejs }}", {
|
|
29
|
+
email: "{{ request.user.email|escapejs }}",
|
|
30
|
+
admin: {{ request.user.is_superuser|yesno:"true,false" }}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
{% endif %}
|
|
35
|
+
{% endblock body_tracking_scripts %}
|