Skip to content

Commit 90d9288

Browse files
Ensure stale essential data is refreshed
This applies to all except auto-download pages. On those pages, we can assume the user clicked to download from the preceding page, and the preceding page set all necessary attribution data. This change also removes fallback values in python code because we cannot reliably know if marketing data is allowed at this point.
1 parent 867caca commit 90d9288

4 files changed

Lines changed: 36 additions & 22 deletions

File tree

media/js/base/download-attribution/download-attribution-init.es6.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import DownloadAttribution from './download-attribution.es6';
88

99
DownloadAttribution.applyAttributionDataToLinks();
1010

11-
if (
12-
document.documentElement.hasAttribute(
13-
'data-stub-attribution-campaign-force'
14-
)
15-
) {
16-
DownloadAttribution.initEssential();
17-
}
11+
// We always want to refresh the essential data
12+
// to avoid an outdated download experience
13+
// If there's new essential data, update
14+
// If there's no essential data, remove
15+
DownloadAttribution.initEssential();

media/js/base/download-attribution/download-attribution.es6.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ const DownloadAttribution = {
754754
DownloadAttribution.COOKIE_MARKETING_RAW_ID
755755
);
756756

757+
// We have last touch essential attribution to avoid a stale download experience
758+
// REMOVE essential data if it is no longer applicable
757759
if (Object.keys(essential).length === 0) {
758760
if (marketing) {
759761
// remove essential only
@@ -801,6 +803,16 @@ const DownloadAttribution = {
801803
}
802804

803805
if (isConsentGranted) {
806+
// We have first touch marketing attribution
807+
// DO NOT UPDATE if we have existing marketing data
808+
if (
809+
DownloadAttribution.getRawCookie(
810+
DownloadAttribution.COOKIE_MARKETING_RAW_ID
811+
)
812+
) {
813+
return;
814+
}
815+
804816
if (!DownloadAttribution.withinAttributionRate()) {
805817
return;
806818
}

media/js/firefox/download/auto-download.es6.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function onTimeout() {
156156
beginFirefoxDownload();
157157
}
158158

159-
// Force cookie update if there is essential data to add
159+
// Force cookie update before download if there is essential data to add
160160
if (
161161
Mozilla.DownloadAttribution !== undefined &&
162162
document.documentElement.hasAttribute(
@@ -172,6 +172,7 @@ if (
172172
timeout = setTimeout(onTimeout, 2000);
173173
Mozilla.DownloadAttribution.initEssential();
174174
} else {
175+
// Otherwise, we can assume an existing cookie has latest data
175176
beginFirefoxDownload();
176177
}
177178

springfield/firefox/views.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,23 @@ def stub_attribution_code(request):
114114
else:
115115
codes[name] = default_value
116116

117-
if codes["source"] == "(not set)" and "referrer" in data:
118-
try:
119-
domain = urlparse(data["referrer"]).netloc
120-
if domain and STUB_VALUE_RE.match(domain):
121-
codes["source"] = domain
122-
codes["medium"] = "referral"
123-
has_value = True
124-
except Exception:
125-
# any problems and we should just ignore it
126-
pass
127-
128-
if not has_value:
129-
codes["source"] = "www.firefox.com"
130-
codes["medium"] = "(none)"
117+
# We are not going to provide fallbacks because we may not have marketing data consent
118+
# Consent checks are in JS, so we will rely on what is provided through JS only
119+
if not waffle.switch("ENABLE_ATTRIBUTION_REFACTOR"):
120+
if codes["source"] == "(not set)" and "referrer" in data:
121+
try:
122+
domain = urlparse(data["referrer"]).netloc
123+
if domain and STUB_VALUE_RE.match(domain):
124+
codes["source"] = domain
125+
codes["medium"] = "referral"
126+
has_value = True
127+
except Exception:
128+
# any problems and we should just ignore it
129+
pass
130+
131+
if not has_value:
132+
codes["source"] = "www.firefox.com"
133+
codes["medium"] = "(none)"
131134

132135
code_data = sign_attribution_codes(codes)
133136
if code_data:

0 commit comments

Comments
 (0)