Skip to content

Commit cb0e469

Browse files
committed
Remove deprecated option for google analytics
1 parent 284e091 commit cb0e469

File tree

2 files changed

+8
-50
lines changed

2 files changed

+8
-50
lines changed

src/pydata_sphinx_theme/__init__.py

+8-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Bootstrap-based sphinx theme from the PyData community
33
"""
44
import os
5-
import warnings
65
from pathlib import Path
76
from functools import lru_cache
87
import json
@@ -86,18 +85,6 @@ def update_config(app, env):
8685

8786
# Add an analytics ID to the site if provided
8887
analytics = theme_options.get("analytics", {})
89-
# deprecated options for Google Analytics
90-
# TODO: deprecate >= v0.12
91-
gid = theme_options.get("google_analytics_id")
92-
if gid:
93-
msg = (
94-
"'google_analytics_id' is deprecated and will be removed in "
95-
"version 0.11, please refer to the documentation "
96-
"and use 'analytics' instead."
97-
)
98-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
99-
analytics.update({"google_analytics_id": gid})
100-
10188
if analytics:
10289
# Plausible analytics
10390
plausible_domain = analytics.get("plausible_analytics_domain")
@@ -112,29 +99,16 @@ def update_config(app, env):
11299
}
113100
app.add_js_file(**kwargs)
114101

115-
# Two types of Google Analytics id.
102+
# Google Analytics
116103
gid = analytics.get("google_analytics_id")
117104
if gid:
118-
# In this case it is "new-style" google analytics
119-
if "G-" in gid:
120-
gid_js_path = f"https://www.googletagmanager.com/gtag/js?id={gid}"
121-
gid_script = f"""
122-
window.dataLayer = window.dataLayer || [];
123-
function gtag(){{ dataLayer.push(arguments); }}
124-
gtag('js', new Date());
125-
gtag('config', '{gid}');
126-
"""
127-
# In this case it is "old-style" google analytics
128-
else:
129-
gid_js_path = "https://www.google-analytics.com/analytics.js"
130-
gid_script = f"""
131-
window.ga = window.ga || function () {{
132-
(ga.q = ga.q || []).push(arguments) }};
133-
ga.l = +new Date;
134-
ga('create', '{gid}', 'auto');
135-
ga('set', 'anonymizeIp', true);
136-
ga('send', 'pageview');
137-
"""
105+
gid_js_path = f"https://www.googletagmanager.com/gtag/js?id={gid}"
106+
gid_script = f"""
107+
window.dataLayer = window.dataLayer || [];
108+
function gtag(){{ dataLayer.push(arguments); }}
109+
gtag('js', new Date());
110+
gtag('config', '{gid}');
111+
"""
138112

139113
# Link the JS files
140114
app.add_js_file(gid_js_path, loading_method="async")

tests/test_build.py

-16
Original file line numberDiff line numberDiff line change
@@ -546,11 +546,6 @@ def test_edit_page_url(sphinx_build_factory, html_context, edit_url):
546546
@pytest.mark.parametrize(
547547
"provider,tags",
548548
[
549-
# TODO: Deprecate old-style analytics config >= 0.12
550-
# new_google_analytics_id
551-
({"html_theme_options.google_analytics_id": "G-XXXXX"}, ["gtag", "G-XXXXX"]),
552-
# old_google_analytics_id
553-
({"html_theme_options.google_analytics_id": "UA-XXXXX"}, ["ga", "UA-XXXXX"]),
554549
# google analytics
555550
(
556551
{"html_theme_options.analytics": {"google_analytics_id": "G-XXXXX"}},
@@ -567,17 +562,6 @@ def test_edit_page_url(sphinx_build_factory, html_context, edit_url):
567562
},
568563
["gtag", "G-XXXXX"],
569564
),
570-
# TODO: Deprecate old-style analytics config >= 0.12
571-
(
572-
{
573-
"html_theme_options.analytics": {
574-
"plausible_analytics_domain": "toto",
575-
"plausible_analytics_url": "http://.../script.js",
576-
},
577-
"html_theme_options.google_analytics_id": "G-XXXXX",
578-
},
579-
["gtag", "G-XXXXX"],
580-
),
581565
],
582566
)
583567
def test_analytics(sphinx_build_factory, provider, tags):

0 commit comments

Comments
 (0)