Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/pydata_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def update_config(app):
gid_script = f"""
window.dataLayer = window.dataLayer || [];
function gtag(){{ dataLayer.push(arguments); }}
gtag('consent', 'default', {{
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
}});
gtag('js', new Date());
gtag('config', '{gid}');
"""
Expand Down
7 changes: 7 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ def test_analytics(sphinx_build_factory, provider, tags) -> None:
tags_found = False
for script in index_html.select("script"):
if script.string and tags[0] in script.string and tags[1] in script.string:
# If the tag is found, make sure the consent mode is also there
if tags[0] == "gtag":
assert "gtag('consent', 'default', {" in script.string
assert "'ad_storage': 'denied'," in script.string
assert "'ad_user_data': 'denied'," in script.string
assert "'ad_personalization': 'denied'," in script.string
assert "'analytics_storage': 'denied'" in script.string
tags_found = True
assert tags_found is True

Expand Down
Loading