WT-964 Refactor stub attribution to download attribution#1296
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1296 +/- ##
==========================================
- Coverage 79.96% 78.95% -1.02%
==========================================
Files 149 152 +3
Lines 9655 10359 +704
==========================================
+ Hits 7721 8179 +458
- Misses 1934 2180 +246 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
stevejalim
reviewed
Apr 29, 2026
stevejalim
reviewed
Apr 29, 2026
8e34134 to
5047f3b
Compare
maureenlholland
commented
Apr 29, 2026
1e53908 to
e945dc7
Compare
e945dc7 to
bafc009
Compare
…analytics data We always want to include essential data for the download. We conditionally want to include analytics data (based on consent status). We also want to simplify the logic of this flow. The existing stub-attribution JS contains a lot of complex, nested conditionals which has resulted in hard-to-debug issues and makes further development difficult. Refactored attribution approach should be gated behind a switch. When that switch is active, the following changes should be applied: REMOVED - stub-attribution-consent (now handled through GTM consent mode) REPLACED - stub-attribution (now download-attribution) - stub-attribution-init (now download-attribution-init) - thanks, thanks-direct, thanks-init (now auto-download) ADDED - download-attribution - completely isolates essential and analytics data (with separate triggers) - download-attribution-init (the default that runs on all pages) - initializes an essential attribution update (the LAST essential information is what we pass to the installer, any previous essential information will be overwritten or removed) - attaches any existing download-attribution information to download links - auto-download (replaces the default init behaviour on pages where downloads should start automatically) - if essential information, adds/updates the download attribution cookie before starting download - if no essential information, starts download immediately UPDATED - Analytics initialization happens inside consent util for GTM analytics storage - Download as default JS no longer contains consent logic (this is already handled with GTM) - RTAMO uses a new template with a forced essential campaign and auto-download JS - Thanks template used auto-download JS
We can trigger initAnalytics based on GTM consent analytics storage This allows consent logic to live in one place and ensures it is consistently applied for analytics download attribution. The search params JS has moved into the site bundle to ensure it is defined at the time the GTM logic runs. Without this change, analytics initialization would always fail at download attribution functional requirements check. In future, we may create a custom GTM trigger that fires based on the analytics storage consent state.
This is a combination of thanks, thanks-init, and thanks-direct logic Copy-pasted with superficial changes: - shouldAutoDownload - getDownloadURL - beginFirefoxDownload - onSuccess - onTimeout Auto-download pages will not use the default download attribution init logic from the stub attribution block. These pages will only create/update download attribution if there is essential data to pass to the download installer. Otherwise, they will attempt to start download immediately. There is a timeout to prevent an overly long wait before download auto-starts (i.e. if the stub attribution service response is slow). This means we prioritize a timely download over passing essential information.
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.
We should only apply defaults for analytics values once we confirm there is a ga4 client id value Otherwise, consider essential only and pass nothing but the campaign
bafc009 to
b7b3b92
Compare
To recreate: - Consent required geo goes to /landing/get and accepts analytics from banner - Analytics information is added to download attribution - Consent required geo goes to /privacy/websites/cookie-settings and updates analytics preference to denied - Analytics information should be removed from download attribution This is commented as a temporary workaround because we are still conditionally loading GTM (and GTAG initialization is related to that). This means there are pages where GTAG is not defined but we might still need to remove pre-existing analytics information. Moving the removal action above the GTAG check ensures it always runs when consent is denied.
…ion-init Update comment to clarify cases covered by the initEssential call
…tion init bundle on base protocol
stevejalim
reviewed
May 20, 2026
stevejalim
reviewed
May 20, 2026
stevejalim
reviewed
May 20, 2026
stevejalim
reviewed
May 20, 2026
stevejalim
approved these changes
May 20, 2026
Collaborator
Author
|
DO NOT MERGE until successful integration tests: https://github.com/mozmeao/springfield/actions/runs/26169062702/job/76981311396 |
maureenlholland
commented
May 26, 2026
| params.remove('attribution_code'); | ||
| params.remove('attribution_sig'); | ||
| return ( | ||
| origin + '?' + window.decodeURIComponent(params.toString()) |
Collaborator
Author
There was a problem hiding this comment.
out-of-scope, future: this is a 1-to-1 port from stub attribution and not related to the separation of essential and analytics refactor work. However, we might want to remove thisdecodeURIComponent wrapper in future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One-line summary
Simplify and clarify download attribution data flow
Significant changes and points to review
Refactored attribution approach should be gated behind a switch:
ENABLE_ATTRIBUTION_REFACTOR.When that switch is active, the following changes should be applied:
REMOVED
REPLACED
ADDED
UPDATED
Rough edges:
thanksprefix in auto-download JSIssue / Bugzilla link
https://mozilla-hub.atlassian.net/browse/WT-964 [moz only]
Follow up work:
Testing
Consent gating
Analytics
should not fire when
should fire
Essential
No download attribution cookie (create)
Analytics
Essential
Existing download attribution cookie (update)
Analytics
Essential
Existing download attribution cookie (remove)
Analytics
Essential
Auto-download
Regression tests
No user-facing change (unless indicated)
RTAMO* auto download (DNT/GPC check no longer needed now we can cleanly remove analytics data according to consent and only apply essential data)
www.firefox.com(currently directing towww.mozilla.org)*Moved to follow-up task: https://mozilla-hub.atlassian.net/browse/WT-1215
Download as default checkbox (should now work for consent required geos, only applying essential data)
Smart Window
/allafter user selections/thanksauto downloadstub-attribution-codeparam/landing/getwith marketing opt-out checkboxFallback campaign
kitcampaign if analytics allowed and no utm_campaign in URL: https://www-demo4.springfield.moz.works/en-US/kit/