-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global FxA CTA experiment for Firefox users (Fixes #6629)
- Loading branch information
1 parent
c7af3f2
commit e76ccd9
Showing
12 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* Global FxA CTA experiment: issue #6629 | ||
*/ | ||
(function() { | ||
'use strict'; | ||
|
||
var nav = document.querySelector('.mzp-c-navigation'); | ||
var SAMPLE_RATE = 0.5; | ||
var COOKIE_EXPIRATION_DAYS = 1; | ||
var COOKIE_ID = 'global-fxa-cta-exp'; | ||
|
||
function isWithinSampleRate() { | ||
return (Math.random() < SAMPLE_RATE) ? true : false; | ||
} | ||
|
||
function cookieExpiresDate(date) { | ||
var d = date || new Date(); | ||
d.setTime(d.getTime() + (COOKIE_EXPIRATION_DAYS * 24 * 60 * 60 * 1000)); | ||
return d.toUTCString(); | ||
} | ||
|
||
function setCookie(cohort) { | ||
Mozilla.Cookies.setItem(COOKIE_ID, cohort, cookieExpiresDate(), '/'); | ||
} | ||
|
||
function getCookie() { | ||
return Mozilla.Cookies.getItem(COOKIE_ID); | ||
} | ||
|
||
function hasCookie() { | ||
return Mozilla.Cookies.hasItem(COOKIE_ID); | ||
} | ||
|
||
function shouldShowFxAButton() { | ||
var cohort; | ||
|
||
// If a cookie already exists then use that value to determine what to show | ||
if (hasCookie()) { | ||
cohort = getCookie(); | ||
} | ||
// Else roll the dice and then set a new cookie. | ||
else { | ||
cohort = isWithinSampleRate() ? 'fxa' : 'download'; | ||
setCookie(cohort); | ||
} | ||
|
||
return cohort === 'fxa' ? true : false; | ||
} | ||
|
||
function showFxAButton() { | ||
nav.classList.add('show-fxa-button'); | ||
|
||
window.dataLayer.push({ | ||
'data-ex-variant': 'accounts-button', | ||
'data-ex-name': 'global-fxa-button' | ||
}); | ||
} | ||
|
||
function showDownloadButton() { | ||
window.dataLayer.push({ | ||
'data-ex-variant': 'download-button', | ||
'data-ex-name': 'global-fxa-button' | ||
}); | ||
} | ||
|
||
function meetsRequirements() { | ||
if (typeof Mozilla.Client === 'undefined' || typeof Mozilla.Cookies === 'undefined') { | ||
return false; | ||
} | ||
|
||
// Respect privacy | ||
if (!Mozilla.Cookies.enabled() || Mozilla.dntEnabled()) { | ||
return false; | ||
} | ||
|
||
// Is the client Firefox desktop and is the navigation present on the current page? | ||
return Mozilla.Client.isFirefoxDesktop && nav; | ||
} | ||
|
||
if (meetsRequirements()) { | ||
if (shouldShowFxAButton()) { | ||
showFxAButton(); | ||
} else { | ||
showDownloadButton(); | ||
} | ||
} | ||
})(); |
This file contains 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
This file contains 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