File tree Expand file tree Collapse file tree
base/download-attribution Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,10 +8,8 @@ import DownloadAttribution from './download-attribution.es6';
88
99DownloadAttribution . 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 ( ) ;
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
160160if (
161161 Mozilla . DownloadAttribution !== undefined &&
162162 document . documentElement . hasAttribute (
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
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments