Skip to content

WT-964 Refactor stub attribution to download attribution#1296

Merged
maureenlholland merged 39 commits into
mainfrom
WT-964--refactor-stub-attribution
May 27, 2026
Merged

WT-964 Refactor stub attribution to download attribution#1296
maureenlholland merged 39 commits into
mainfrom
WT-964--refactor-stub-attribution

Conversation

@maureenlholland

@maureenlholland maureenlholland commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

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

  • 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 only
  • 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 uses auto-download JS

Rough edges:

  • data validation mixes rtamo-specific validation with general content length validation
  • leftover thanks prefix in auto-download JS

Issue / Bugzilla link

https://mozilla-hub.atlassian.net/browse/WT-964 [moz only]

  • links to docs on current behaviour and refactor plan on ticket

Follow up work:

Testing

Consent gating

Analytics

  • should not fire when

    • consent required geo and no pref allowing analytics
    • any geo and DNT
    • any geo and GPC
    • any geo and pref denying analytics
  • should fire

    • consent required geo and pref allowing analytics
    • not consent required geo and no explicit denial signal (DNT/GPC/pref)

Essential

  • should always fire
    • consent required geo and pref allowing analytics
    • not consent required geo and no explicit denial signal (DNT/GPC/pref)
    • consent required geo and no pref allowing analytics
    • any geo and DNT
    • any geo and GPC
    • any geo and pref denying analytics

No download attribution cookie (create)

Analytics

  • Add if consent gates pass

Essential

  • Add if essential forced campaign in HTML
  • Add if checked checkbox for essential campaign

Existing download attribution cookie (update)

Analytics

  • add if consent granted
  • preserve if essential update happens
  • preserve if new analytics data (first touch, pre-existing wins over new)

Essential

  • preserve if analytics update happens
  • add new essential data to replace old (last touch, new wins over pre-existing)

Existing download attribution cookie (remove)

Analytics

  • remove if consent denied

Essential

  • remove if user unchecks essential feature checkbox (i.e. download as default)
  • remove if user leaves essential feature page before clicking download CTA (i.e. smart window)
    • this covers the case where essential data is now stale and would provide an unexpected feature flow on download
    • auto-download page is an exception, where we can assume any essential data is from the immediately preceding page and is the expected feature flow

Auto-download

  • should start download immediately with existing download attribution if no new essential data on page
  • should create/update essential data attribution before download if new essential data is on page (i.e. rtamo)

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)

Download as default checkbox (should now work for consent required geos, only applying essential data)

Smart Window

/all after user selections

/thanks auto download

/landing/get with marketing opt-out checkbox

Fallback campaign

@maureenlholland maureenlholland added the WIP Work in progress label Apr 23, 2026
@codecov

codecov Bot commented Apr 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.94595% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.95%. Comparing base (e0d69b9) to head (9707c21).
⚠️ Report is 29 commits behind head on main.

Files with missing lines Patch % Lines
springfield/firefox/views.py 45.94% 20 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread media/js/base/download-attribution/download-attribution-init.es6.js Outdated
Comment thread media/js/firefox/download/auto-download.es6.js
@maureenlholland maureenlholland force-pushed the WT-964--refactor-stub-attribution branch 2 times, most recently from 8e34134 to 5047f3b Compare April 29, 2026 14:33
Comment thread springfield/firefox/views.py Outdated
@maureenlholland maureenlholland force-pushed the WT-964--refactor-stub-attribution branch 3 times, most recently from 1e53908 to e945dc7 Compare May 7, 2026 17:13
@maureenlholland maureenlholland force-pushed the WT-964--refactor-stub-attribution branch from e945dc7 to bafc009 Compare May 13, 2026 13:46
…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
@maureenlholland maureenlholland force-pushed the WT-964--refactor-stub-attribution branch from bafc009 to b7b3b92 Compare May 13, 2026 14:44
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.
@maureenlholland maureenlholland changed the title WT-964 Refactor stub attribution WT-964 Refactor stub attribution to download attribution May 20, 2026
Comment thread media/js/base/download-attribution/download-attribution.es6.js Outdated
Comment thread media/js/base/download-attribution/download-attribution.es6.js
Comment thread media/js/base/download-attribution/download-attribution.es6.js
Comment thread media/js/base/download-attribution/download-attribution.es6.js
@maureenlholland maureenlholland added Do Not Merge Don't do it. and removed WIP Work in progress labels May 20, 2026
@maureenlholland

maureenlholland commented May 20, 2026

Copy link
Copy Markdown
Collaborator Author

DO NOT MERGE until some final code updates & passing integration tests & demo test run

successful integration tests: https://github.com/mozmeao/springfield/actions/runs/26169062702/job/76981311396

params.remove('attribution_code');
params.remove('attribution_sig');
return (
origin + '?' + window.decodeURIComponent(params.toString())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@maureenlholland maureenlholland removed the Do Not Merge Don't do it. label May 26, 2026
@maureenlholland maureenlholland marked this pull request as ready for review May 26, 2026 12:29
@maureenlholland maureenlholland merged commit 6cd91cd into main May 27, 2026
6 checks passed
@maureenlholland maureenlholland deleted the WT-964--refactor-stub-attribution branch May 27, 2026 15:31
@data-sync-user data-sync-user mentioned this pull request May 28, 2026
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants