Compare commits
2
Commits
master
...
d6bed439d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6bed439d7 | ||
|
|
351994673a |
@@ -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'
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var CONSENT_KEY = 'aiml_analytics_consent';
|
||||
var NOTICE_KEY = 'aiml_analytics_notice';
|
||||
var LEGACY_CONSENT_KEY = 'aiml_analytics_consent';
|
||||
var LEGACY_DISABLED_KEY = 'tianji.disabled';
|
||||
var configEl = document.getElementById('tianji-config');
|
||||
if (!configEl) {
|
||||
return;
|
||||
@@ -10,19 +12,26 @@
|
||||
var trackerUrl = configEl.dataset.trackerUrl;
|
||||
var websiteId = configEl.dataset.websiteId;
|
||||
var userId = configEl.dataset.userId || '';
|
||||
var pendingConsentEvent = false;
|
||||
|
||||
function getConsent() {
|
||||
function getStorageItem(key) {
|
||||
try {
|
||||
return localStorage.getItem(CONSENT_KEY);
|
||||
return localStorage.getItem(key);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function setConsent(value) {
|
||||
function setStorageItem(key, value) {
|
||||
try {
|
||||
localStorage.setItem(CONSENT_KEY, value);
|
||||
localStorage.setItem(key, value);
|
||||
} catch (e) {
|
||||
/* ignore storage errors */
|
||||
}
|
||||
}
|
||||
|
||||
function removeStorageItem(key) {
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch (e) {
|
||||
/* ignore storage errors */
|
||||
}
|
||||
@@ -71,51 +80,44 @@
|
||||
|
||||
script.onload = function () {
|
||||
identifyUser();
|
||||
if (pendingConsentEvent) {
|
||||
trackEvent('consent_accepted');
|
||||
pendingConsentEvent = false;
|
||||
}
|
||||
document.dispatchEvent(new CustomEvent('tianji:ready'));
|
||||
};
|
||||
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
function acceptTracking() {
|
||||
setConsent('accepted');
|
||||
hideBanner();
|
||||
try {
|
||||
localStorage.removeItem('tianji.disabled');
|
||||
} catch (e) {
|
||||
/* ignore storage errors */
|
||||
function migrateLegacyConsent() {
|
||||
var legacyConsent = getStorageItem(LEGACY_CONSENT_KEY);
|
||||
var legacyDisabled = getStorageItem(LEGACY_DISABLED_KEY);
|
||||
|
||||
if (legacyConsent === 'accepted') {
|
||||
setStorageItem(NOTICE_KEY, 'acknowledged');
|
||||
removeStorageItem(LEGACY_CONSENT_KEY);
|
||||
removeStorageItem(LEGACY_DISABLED_KEY);
|
||||
return 'migrated_acknowledged';
|
||||
}
|
||||
pendingConsentEvent = true;
|
||||
loadTracker();
|
||||
|
||||
if (legacyConsent === 'declined' || legacyDisabled === '1') {
|
||||
removeStorageItem(LEGACY_CONSENT_KEY);
|
||||
removeStorageItem(LEGACY_DISABLED_KEY);
|
||||
return 'migrated_declined';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function declineTracking() {
|
||||
setConsent('declined');
|
||||
function acknowledgeNotice() {
|
||||
setStorageItem(NOTICE_KEY, 'acknowledged');
|
||||
hideBanner();
|
||||
try {
|
||||
localStorage.setItem('tianji.disabled', '1');
|
||||
} catch (e) {
|
||||
/* ignore storage errors */
|
||||
}
|
||||
if (window.aimlTrack) {
|
||||
window.aimlTrack('consent_declined');
|
||||
}
|
||||
window.aimlTrackWhenReady('notice_acknowledged');
|
||||
}
|
||||
|
||||
function bindBannerControls() {
|
||||
var acceptBtn = document.getElementById('cookie-consent-accept');
|
||||
var declineBtn = document.getElementById('cookie-consent-decline');
|
||||
var acknowledgeBtn = document.getElementById('cookie-consent-acknowledge');
|
||||
var manageLinks = document.querySelectorAll('[data-open-cookie-preferences]');
|
||||
|
||||
if (acceptBtn) {
|
||||
acceptBtn.addEventListener('click', acceptTracking);
|
||||
}
|
||||
if (declineBtn) {
|
||||
declineBtn.addEventListener('click', declineTracking);
|
||||
if (acknowledgeBtn) {
|
||||
acknowledgeBtn.addEventListener('click', acknowledgeNotice);
|
||||
}
|
||||
manageLinks.forEach(function (link) {
|
||||
link.addEventListener('click', function (event) {
|
||||
@@ -140,16 +142,14 @@
|
||||
});
|
||||
};
|
||||
|
||||
function initConsent() {
|
||||
function initNotice() {
|
||||
bindBannerControls();
|
||||
loadTracker();
|
||||
|
||||
var consent = getConsent();
|
||||
if (consent === 'accepted') {
|
||||
hideBanner();
|
||||
loadTracker();
|
||||
return;
|
||||
}
|
||||
if (consent === 'declined') {
|
||||
var migration = migrateLegacyConsent();
|
||||
var notice = getStorageItem(NOTICE_KEY);
|
||||
|
||||
if (notice === 'acknowledged' || migration === 'migrated_acknowledged') {
|
||||
hideBanner();
|
||||
return;
|
||||
}
|
||||
@@ -157,5 +157,5 @@
|
||||
showBanner();
|
||||
}
|
||||
|
||||
initConsent();
|
||||
initNotice();
|
||||
})();
|
||||
|
||||
@@ -137,15 +137,14 @@
|
||||
<div id="cookie-consent-banner" class="cookie-consent-banner" hidden role="dialog" aria-modal="true"
|
||||
aria-labelledby="cookie-consent-title" aria-describedby="cookie-consent-description">
|
||||
<div class="cookie-consent-content">
|
||||
<h2 id="cookie-consent-title" class="visually-hidden">Cookie consent</h2>
|
||||
<h2 id="cookie-consent-title" class="visually-hidden">Analytics notice</h2>
|
||||
<p class="cookie-consent-text" id="cookie-consent-description">
|
||||
<span class="cookie-consent-text-full">We use analytics tracking to understand how visitors use our site. Tracking runs only if you accept.
|
||||
<span class="cookie-consent-text-full">We use analytics to understand how visitors use our site. This helps us improve performance and content.
|
||||
See our <a href="{% url 'terms_of_service' %}">Terms of Service & Privacy Policy</a> for details.</span>
|
||||
<span class="cookie-consent-text-short">We use analytics if you accept. <a href="{% url 'terms_of_service' %}">Privacy Policy</a></span>
|
||||
<span class="cookie-consent-text-short">We use analytics on this site. <a href="{% url 'terms_of_service' %}">Privacy Policy</a></span>
|
||||
</p>
|
||||
<div class="cookie-consent-actions">
|
||||
<button type="button" id="cookie-consent-decline" class="btn btn-outline">Decline</button>
|
||||
<button type="button" id="cookie-consent-accept" class="btn">Accept Analytics</button>
|
||||
<button type="button" id="cookie-consent-acknowledge" class="btn">Acknowledge</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<ul>
|
||||
<li><strong>Information you provide:</strong> name, email address, message content, and other details submitted through contact forms or account-related requests.</li>
|
||||
<li><strong>Account information:</strong> username and authentication data for authorized users of internal tools.</li>
|
||||
<li><strong>Usage and analytics data:</strong> if you accept analytics in our cookie banner, we collect information about how you interact with the site, as described in Section 4.2.</li>
|
||||
<li><strong>Usage and analytics data:</strong> information about how you interact with the site, as described in Section 4.2.</li>
|
||||
<li><strong>Technical information:</strong> browser type, device type, operating system, language, referring URLs, and similar data collected automatically when you use the site.</li>
|
||||
</ul>
|
||||
<p>
|
||||
@@ -63,9 +63,9 @@
|
||||
<h3>4.2 Analytics and Usage Tracking</h3>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>When you accept analytics, we may collect information such as:</p>
|
||||
<p>We may collect information such as:</p>
|
||||
<ul>
|
||||
<li>Pages viewed and navigation paths</li>
|
||||
<li>Approximate geographic location derived from truncated IP addresses</li>
|
||||
@@ -76,16 +76,16 @@
|
||||
</ul>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
|
||||
<h3>4.3 Cookies and Local Storage</h3>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
@@ -126,7 +126,7 @@
|
||||
<h3>4.7 Your Choices and Rights</h3>
|
||||
<p>You can:</p>
|
||||
<ul>
|
||||
<li>Accept or decline analytics tracking through our cookie banner or the cookie preferences link in the footer</li>
|
||||
<li>Acknowledge our analytics notice through the banner or review it again using the cookie preferences link in the footer</li>
|
||||
<li>Contact us to request access to, correction of, or deletion of personal information you have provided, subject to applicable law</li>
|
||||
<li>Disable non-essential browser storage or cookies through your browser settings, though essential site features may not function properly</li>
|
||||
</ul>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user