From 98763c00c5ea8a371d30fb6f128b09e168157806 Mon Sep 17 00:00:00 2001 From: Ryan Westfall Date: Thu, 2 Jul 2026 06:50:40 -0500 Subject: [PATCH] Switch Tianji tracking from opt-in consent to acknowledge notice. Load analytics on page load so visitors who never interact still produce data, while an informational banner lets users acknowledge the practice. Migrate legacy declined and accepted consent values so prior opt-outs are cleared and tracking resumes. Closes #7 --- company_site/company_site/settings.py | 2 +- company_site/public/templates/base.html | 9 ++++----- .../templates/public/terms_of_service.html | 16 ++++++++-------- company_site/public/tests.py | 8 ++++++-- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/company_site/company_site/settings.py b/company_site/company_site/settings.py index b674e9a..5fcbf01 100644 --- a/company_site/company_site/settings.py +++ b/company_site/company_site/settings.py @@ -156,6 +156,6 @@ EMAIL_USE_TLS = True LOGIN_REDIRECT_URL = '/' LOGOUT_REDIRECT_URL = '/' -# Tianji analytics (loaded only after user consent) +# Tianji analytics (loaded on page load; users acknowledge via notice banner) TIANJI_TRACKER_URL = 'https://tianji.aimloperations.com/tracker.js' TIANJI_WEBSITE_ID = 'cm7w80pyy020oddswy2evl957' diff --git a/company_site/public/templates/base.html b/company_site/public/templates/base.html index eee74f3..c5b47a1 100644 --- a/company_site/public/templates/base.html +++ b/company_site/public/templates/base.html @@ -137,15 +137,14 @@ diff --git a/company_site/public/templates/public/terms_of_service.html b/company_site/public/templates/public/terms_of_service.html index 79e76c7..8d78377 100644 --- a/company_site/public/templates/public/terms_of_service.html +++ b/company_site/public/templates/public/terms_of_service.html @@ -52,7 +52,7 @@

@@ -63,9 +63,9 @@

4.2 Analytics and Usage Tracking

We use Tianji, a self-hosted analytics platform, to understand how visitors use our website and internal - tools. Tracking is enabled only after you provide consent through our cookie banner. + tools. Analytics run when you use the site so we can measure usage and improve the experience.

-

When you accept analytics, we may collect information such as:

+

We may collect information such as:

We do not use Tianji to sell your personal information. Analytics data helps us improve site performance, - content, and product usability. You may decline analytics at any time using the cookie preferences link - in the site footer. If you decline, the analytics script will not load. + content, and product usability. We show an analytics notice when you first visit the site. You can review it + again at any time using the cookie preferences link in the site footer.

- We store your consent choice locally in your browser so we can remember your preference on future visits. + We store your acknowledgement locally in your browser so we do not show the notice on every visit.

4.3 Cookies and Local Storage

- In addition to analytics consent storage, our site uses essential cookies and session storage required for + In addition to analytics notice storage, our site uses essential cookies and session storage required for authentication, security (including CSRF protection), and basic site functionality. These essential technologies are necessary for the site to operate and are not used for marketing analytics.

@@ -126,7 +126,7 @@

4.7 Your Choices and Rights

You can:

diff --git a/company_site/public/tests.py b/company_site/public/tests.py index c6e6da0..1c35f3c 100644 --- a/company_site/public/tests.py +++ b/company_site/public/tests.py @@ -115,16 +115,20 @@ class ContactViewTests(TestCase): @override_settings(DEBUG=True, TIANJI_ENABLED=True) class TianjiTrackingTests(TestCase): - def test_homepage_includes_consent_banner_when_enabled(self): + def test_homepage_includes_analytics_notice_when_enabled(self): response = self.client.get(reverse("public_index")) self.assertEqual(response.status_code, 200) self.assertContains(response, "cookie-consent-banner") + self.assertContains(response, "cookie-consent-acknowledge") + self.assertContains(response, "Acknowledge") + self.assertNotContains(response, "cookie-consent-decline") + self.assertNotContains(response, "Accept Analytics") self.assertContains(response, "tianji-config") self.assertContains(response, "tianji-consent.js") @override_settings(TIANJI_ENABLED=False) - def test_homepage_omits_consent_banner_when_disabled(self): + def test_homepage_omits_analytics_notice_when_disabled(self): response = self.client.get(reverse("public_index")) self.assertEqual(response.status_code, 200) -- 2.54.0