Skip to content

Commit 6f20680

Browse files
authored
Revert "Remove set-as-default experiment code (Fixes #16095) (#16096)" (#16112)
This reverts commit 52f448f.
1 parent 70a5f65 commit 6f20680

File tree

11 files changed

+962
-2
lines changed

11 files changed

+962
-2
lines changed

bedrock/firefox/templates/firefox/new/desktop/download.html

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
{% extends "firefox/new/desktop/base.html" %}
1010

11+
{% set show_firefox_default_experiment = switch('experiment-firefox-new-default', ['en']) and country_code in ['US', 'CA'] %}
12+
13+
{% block experiments %}
14+
{% if show_firefox_default_experiment %}
15+
{{ js_bundle('experiment-firefox-new-default') }}
16+
{% endif %}
17+
{% endblock %}
18+
1119
{% set referrals = '?utm_source=www.mozilla.org&utm_medium=referral&utm_campaign=firefox-desktop' %}
1220
{% set ios_url = app_store_url('firefox', 'mozilla-org-firefox-new') %}
1321

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{#
2+
This Source Code Form is subject to the terms of the Mozilla Public
3+
License, v. 2.0. If a copy of the MPL was not distributed with this
4+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
#}
6+
7+
{% extends "firefox/new/desktop/download.html" %}
8+
9+
{% block experiments %}
10+
{{ js_bundle('experiment-firefox-new-default') }}
11+
{% endblock %}
12+
13+
{% block extrahead %}
14+
{{ super() }}
15+
{{ css_bundle('experiment-firefox-new-default') }}
16+
{% endblock %}
17+
18+
{% macro default_browser_checkbox(id='default-browser-checkbox') -%}
19+
<label for="{{ id }}" class="default-browser-checkbox-label hidden">
20+
<input type="checkbox" id="{{ id }}" class="default-browser-checkbox-input">
21+
Set Firefox as your default browser.
22+
</label>
23+
{%- endmacro %}
24+
25+
{% block primary_cta %}
26+
{{ default_browser_checkbox(id='default-browser-checkbox-primary') }}
27+
{{ download_firefox_thanks(dom_id='download-primary', locale_in_transition=True, download_location='primary cta') }}
28+
{% endblock %}
29+
30+
{% block features_cta %}
31+
{{ default_browser_checkbox(id='default-browser-checkbox-features') }}
32+
{{ download_firefox_thanks(dom_id='download-features', locale_in_transition=True, download_location='features cta') }}
33+
{% endblock %}
34+
35+
{% block discover_cta %}
36+
{{ default_browser_checkbox(id='default-browser-checkbox-discover') }}
37+
{{ download_firefox_thanks(dom_id='download-discover', locale_in_transition=True, download_location='discover cta') }}
38+
{% endblock %}
39+
40+
{% block js %}
41+
{{ js_bundle('firefox-new-default-opt-out') }}
42+
{% endblock %}

bedrock/firefox/views.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -753,14 +753,15 @@ class NewView(L10nTemplateView):
753753
ftl_files_map = {
754754
"firefox/new/basic/base_download.html": ["firefox/new/download"],
755755
"firefox/new/desktop/download.html": ["firefox/new/desktop"],
756+
"firefox/new/desktop/experiment-firefox-new-default.html": ["firefox/new/desktop"],
756757
}
757758
activation_files = [
758759
"firefox/new/download",
759760
"firefox/new/desktop",
760761
]
761762

762763
# place expected ?v= values in this list
763-
variations = []
764+
variations = ["treatment", "control"]
764765

765766
def get(self, *args, **kwargs):
766767
# Remove legacy query parameters (Bug 1236791)
@@ -801,13 +802,18 @@ def get_context_data(self, **kwargs):
801802
def get_template_names(self):
802803
variation = self.request.GET.get("variation", None)
803804
experience = self.request.GET.get("xv", None)
805+
locale = l10n_utils.get_locale(self.request)
806+
country = get_country_from_request(self.request)
804807

805808
# ensure variant matches pre-defined value
806809
if variation not in self.variations:
807810
variation = None
808811

809812
if ftl_file_is_active("firefox/new/desktop") and experience != "basic":
810-
template = "firefox/new/desktop/download.html"
813+
if variation == "treatment" and locale in ["en-US", "en-CA"] and country in ["US", "CA"]:
814+
template = "firefox/new/desktop/experiment-firefox-new-default.html"
815+
else:
816+
template = "firefox/new/desktop/download.html"
811817
else:
812818
template = "firefox/new/basic/base_download.html"
813819

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
@use '~@mozilla-protocol/core/protocol/css/includes/lib' as *;
6+
7+
.default-browser-checkbox-label {
8+
margin: 0 auto $spacing-lg;
9+
font-weight: normal;
10+
display: block;
11+
width: max-content;
12+
13+
&.hidden {
14+
display: none;
15+
}
16+
17+
input[type="checkbox"] {
18+
margin-right: $spacing-sm;
19+
vertical-align: top;
20+
}
21+
22+
.c-intro-download & {
23+
margin: 0 0 $spacing-lg;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
import {
8+
hasConsentCookie,
9+
getConsentCookie
10+
} from '../../../base/consent/utils.es6';
11+
12+
const experimentCookieID = 'download-as-default';
13+
14+
const utmParams = [
15+
'utm_source=',
16+
'utm_medium=',
17+
'utm_campaign=',
18+
'utm_term=',
19+
'utm_content='
20+
];
21+
22+
function meetsExperimentCriteria(platform, params) {
23+
// Experiment specific feature detection.
24+
if (
25+
typeof window.URL !== 'function' ||
26+
typeof window.URLSearchParams !== 'function' ||
27+
!window.history.replaceState
28+
) {
29+
return false;
30+
}
31+
32+
// Experiment should only trigger for Windows.
33+
if (platform !== 'windows') {
34+
return false;
35+
}
36+
37+
// Don't enter into experiment if cookies are disabled.
38+
if (!Mozilla.Cookies.enabled()) {
39+
return false;
40+
}
41+
42+
// Don't enter into experiment if visitor has previously rejected analytics.
43+
if (hasConsentCookie()) {
44+
const cookie = getConsentCookie();
45+
46+
if (!cookie.analytics) {
47+
return false;
48+
}
49+
}
50+
51+
/**
52+
* Don't enter into experiment if there are any existing UTM parameters in
53+
* the page URL. We do not want to clobber those and overwrite existing
54+
* campaign data.
55+
*/
56+
if (params) {
57+
const queryString = decodeURIComponent(params);
58+
return utmParams.every((param) => {
59+
return queryString.indexOf(param) === -1;
60+
});
61+
}
62+
63+
// Don't enter into experiment if we already have an attribution cookie.
64+
if (
65+
(Mozilla.Cookies.hasItem('moz-stub-attribution-code') ||
66+
Mozilla.Cookies.hasItem('moz-stub-attribution-sig')) &&
67+
!Mozilla.Cookies.hasItem(experimentCookieID)
68+
) {
69+
return false;
70+
}
71+
72+
return true;
73+
}
74+
75+
export { meetsExperimentCriteria, experimentCookieID };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
import TrafficCop from '@mozmeao/trafficcop';
8+
import { isApprovedToRun } from '../../../base/experiment-utils.es6';
9+
import {
10+
meetsExperimentCriteria,
11+
experimentCookieID
12+
} from './default-experiment-criteria.es6';
13+
14+
const href = window.location.href;
15+
const ATTRIBUTION_COOKIE_CODE_ID = 'moz-stub-attribution-code';
16+
const ATTRIBUTION_COOKIE_SIGNATURE_ID = 'moz-stub-attribution-sig';
17+
18+
if (typeof window.dataLayer === 'undefined') {
19+
window.dataLayer = [];
20+
}
21+
22+
/**
23+
* Sets a cookie to remember which experiment variation has been seen.
24+
* @param {Object} traffic cop config
25+
*/
26+
function setVariationCookie(exp) {
27+
// set cookie to expire in 24 hours
28+
const date = new Date();
29+
date.setTime(date.getTime() + 1 * 24 * 60 * 60 * 1000);
30+
const expires = date.toUTCString();
31+
32+
window.Mozilla.Cookies.setItem(
33+
exp.id,
34+
exp.chosenVariation,
35+
expires,
36+
undefined,
37+
undefined,
38+
false,
39+
'lax'
40+
);
41+
}
42+
43+
/**
44+
* Removes existing stub attribution cookie
45+
*/
46+
function removeAttributionCookie() {
47+
window.Mozilla.Cookies.removeItem(
48+
ATTRIBUTION_COOKIE_CODE_ID,
49+
'/',
50+
undefined,
51+
false,
52+
'lax'
53+
);
54+
55+
window.Mozilla.Cookies.removeItem(
56+
ATTRIBUTION_COOKIE_SIGNATURE_ID,
57+
'/',
58+
undefined,
59+
false,
60+
'lax'
61+
);
62+
}
63+
64+
const init = () => {
65+
if (
66+
href.indexOf('experiment=download-as-default&variation=control') !== -1
67+
) {
68+
window.dataLayer.push({
69+
event: 'experiment_view',
70+
id: experimentCookieID,
71+
variant: 'control'
72+
});
73+
} else if (
74+
href.indexOf('experiment=download-as-default&variation=treatment') !==
75+
-1
76+
) {
77+
/**
78+
* People only enter into this experiment if they do not already have stub
79+
* attribution data. However there's still the edge case that someone may
80+
* not download right away, and return back later. If that's the case,
81+
* then we don't know if they checked or unchecked the input originally.
82+
* To circumvent this, we delete their original attribution cookie,
83+
* which will then be created fresh when they load the page again.
84+
*/
85+
if (
86+
window.Mozilla.Cookies.hasItem(ATTRIBUTION_COOKIE_CODE_ID) ||
87+
window.Mozilla.Cookies.hasItem(ATTRIBUTION_COOKIE_SIGNATURE_ID)
88+
) {
89+
removeAttributionCookie();
90+
}
91+
92+
window.dataLayer.push({
93+
event: 'experiment_view',
94+
id: experimentCookieID,
95+
variant: 'treatment'
96+
});
97+
} else if (TrafficCop) {
98+
if (
99+
isApprovedToRun() &&
100+
meetsExperimentCriteria(
101+
window.site.platform,
102+
window.location.search
103+
)
104+
) {
105+
const cop = new TrafficCop({
106+
id: experimentCookieID,
107+
variations: {
108+
'experiment=download-as-default&variation=control': 25,
109+
'experiment=download-as-default&variation=treatment&utm_source=www.mozilla.org&utm_campaign=SET_DEFAULT_BROWSER': 25
110+
}
111+
});
112+
cop.init();
113+
114+
setVariationCookie(cop);
115+
}
116+
}
117+
};
118+
119+
init();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
import DefaultOptOut from './default-opt-out.es6.js';
8+
9+
DefaultOptOut.init();

0 commit comments

Comments
 (0)