From 008524ef2aab7f7bbcfd206f1c400da503f81a68 Mon Sep 17 00:00:00 2001 From: Alex Gibson Date: Mon, 13 Jan 2025 12:03:02 +0000 Subject: [PATCH] Add UK influencer campaign page (Fixes #15841) --- bedrock/base/templates/base-protocol.html | 2 +- .../firefox/landing/productivity.html | 34 +++ .../firefox/new/desktop/download.html | 13 +- bedrock/firefox/urls.py | 2 + .../firefox/landing/smi-download-init.es6.js | 9 + media/js/firefox/landing/smi-download.es6.js | 48 ++++ media/static-bundles.json | 6 + .../unit/spec/firefox/landing/smi-download.js | 260 ++++++++++++++++++ 8 files changed, 369 insertions(+), 5 deletions(-) create mode 100644 bedrock/firefox/templates/firefox/landing/productivity.html create mode 100644 media/js/firefox/landing/smi-download-init.es6.js create mode 100644 media/js/firefox/landing/smi-download.es6.js create mode 100644 tests/unit/spec/firefox/landing/smi-download.js diff --git a/bedrock/base/templates/base-protocol.html b/bedrock/base/templates/base-protocol.html index 598554c3ab1..10410ede89b 100644 --- a/bedrock/base/templates/base-protocol.html +++ b/bedrock/base/templates/base-protocol.html @@ -150,7 +150,7 @@ {% endblock %} diff --git a/bedrock/firefox/templates/firefox/landing/productivity.html b/bedrock/firefox/templates/firefox/landing/productivity.html new file mode 100644 index 00000000000..7ef38cfddda --- /dev/null +++ b/bedrock/firefox/templates/firefox/landing/productivity.html @@ -0,0 +1,34 @@ +{# + 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 https://mozilla.org/MPL/2.0/. +#} + +{% extends "firefox/new/desktop/download.html" %} + +{% block canonical_urls %}{% endblock %} + +{% set win_smi_download_id = 'partner-firefox-release-smi-smi-001-stub' %} +{% set mac_smi_download_id = 'partner-firefox-release-smi-smi-001' %} + +{% block string_data %} + data-win-smi-id="{{ win_smi_download_id }}" + data-mac-smi-id="{{ mac_smi_download_id }}" +{% endblock %} + +{% block primary_cta %} + {{ download_firefox(dom_id='download-primary', force_direct=True, download_location='primary cta') }} +{% endblock %} + +{% block features_cta %} + {{ download_firefox(dom_id='download-features', force_direct=True, download_location='features cta') }} +{% endblock %} + +{% block discover_cta %} + {{ download_firefox(dom_id='download-discover', force_direct=True, download_location='discover cta') }} +{% endblock %} + +{% block js %} + {{ super() }} + {{ js_bundle('firefox_smi_download') }} +{% endblock %} diff --git a/bedrock/firefox/templates/firefox/new/desktop/download.html b/bedrock/firefox/templates/firefox/new/desktop/download.html index 654b7d9a828..b4a9666b528 100644 --- a/bedrock/firefox/templates/firefox/new/desktop/download.html +++ b/bedrock/firefox/templates/firefox/new/desktop/download.html @@ -89,7 +89,9 @@

{{ ftl('firef

{{ ftl('firefox-desktop-download-get-the-browser') }}

{{ ftl('firefox-desktop-download-no-shady') }}

- {{ download_firefox_thanks(locale_in_transition=True, download_location='primary cta') }} + {% block primary_cta %} + {{ download_firefox_thanks(locale_in_transition=True, download_location='primary cta') }} + {% endblock %} @@ -384,8 +386,9 @@

{{ ftl('firefox-desktop-download-customize-your-brows

- {{ download_firefox_thanks(dom_id='download-features', locale_in_transition=True, download_location='features cta') }} - + {% block features_cta %} + {{ download_firefox_thanks(dom_id='download-features', locale_in_transition=True, download_location='features cta') }} + {% endblock %} @@ -545,7 +548,9 @@

{{ ftl('firefox-desktop-download-picture-in-picture')

{{ ftl('firefox-desktop-download-from-watching-a') }}

- {{ download_firefox_thanks(dom_id='download-discover', locale_in_transition=True, download_location='discover cta') }} + {% block discover_cta %} + {{ download_firefox_thanks(dom_id='download-discover', locale_in_transition=True, download_location='discover cta') }} + {% endblock %}
diff --git a/bedrock/firefox/urls.py b/bedrock/firefox/urls.py index 034f19e08be..151014904d6 100644 --- a/bedrock/firefox/urls.py +++ b/bedrock/firefox/urls.py @@ -270,6 +270,8 @@ "firefox/firefox-20th/index.html", active_locales=["de", "fr", "en-US", "en-CA", "en-GB"], ), + # Issue 15841 - UK influencer campaign + page("firefox/landing/productivity/", "firefox/landing/productivity.html", ftl_files="firefox/new/desktop", active_locales="en-GB"), ) # Contentful diff --git a/media/js/firefox/landing/smi-download-init.es6.js b/media/js/firefox/landing/smi-download-init.es6.js new file mode 100644 index 00000000000..ce0b4fe3df7 --- /dev/null +++ b/media/js/firefox/landing/smi-download-init.es6.js @@ -0,0 +1,9 @@ +/* + * 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 https://mozilla.org/MPL/2.0/. + */ + +import SMIDownload from './smi-download.es6'; + +SMIDownload.init(); diff --git a/media/js/firefox/landing/smi-download.es6.js b/media/js/firefox/landing/smi-download.es6.js new file mode 100644 index 00000000000..7abc8892a02 --- /dev/null +++ b/media/js/firefox/landing/smi-download.es6.js @@ -0,0 +1,48 @@ +/* + * 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 https://mozilla.org/MPL/2.0/. + */ + +const SMIDownload = {}; + +let winDownloadID; +let macDownloadID; + +SMIDownload.createCustomDownloadURL = (link, id) => { + const url = new URL(link.href); + url.searchParams.set('product', id); + link.href = url; +}; + +SMIDownload.replaceWithCustomDownloadLinks = () => { + const downloadLinksWin = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="win"]' + ) + ); + const downloadLinksMac = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="osx"]' + ) + ); + + downloadLinksWin.every((link) => + SMIDownload.createCustomDownloadURL(link, winDownloadID) + ); + downloadLinksMac.every((link) => + SMIDownload.createCustomDownloadURL(link, macDownloadID) + ); +}; + +SMIDownload.init = () => { + const strings = document.getElementById('strings'); + winDownloadID = strings.getAttribute('data-win-smi-id'); + macDownloadID = strings.getAttribute('data-mac-smi-id'); + + if (typeof window.URL === 'function' && winDownloadID && macDownloadID) { + SMIDownload.replaceWithCustomDownloadLinks(); + } +}; + +export default SMIDownload; diff --git a/media/static-bundles.json b/media/static-bundles.json index fe4490e39c8..3feb5b29def 100644 --- a/media/static-bundles.json +++ b/media/static-bundles.json @@ -1782,6 +1782,12 @@ "js/base/banners/fundraiser-experiment.es6.js" ], "name": "fundraising-banner-experiment" + }, + { + "files": [ + "js/firefox/landing/smi-download-init.es6.js" + ], + "name": "firefox_smi_download" } ] } diff --git a/tests/unit/spec/firefox/landing/smi-download.js b/tests/unit/spec/firefox/landing/smi-download.js new file mode 100644 index 00000000000..b560a7bf5aa --- /dev/null +++ b/tests/unit/spec/firefox/landing/smi-download.js @@ -0,0 +1,260 @@ +/* + * 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 https://mozilla.org/MPL/2.0/. + */ + +/* For reference read the Jasmine and Sinon docs + * Jasmine docs: https://jasmine.github.io/ + * Sinon docs: http://sinonjs.org/docs/ + */ + +import SMIDownload from '../../../../../media/js/firefox/landing/smi-download.es6'; + +describe('smi-download.es6.js', function () { + describe('init()', function () { + beforeEach(function () { + const strings = `
`; + + const button = ``; + + document.body.insertAdjacentHTML('beforeend', strings); + document.body.insertAdjacentHTML('beforeend', button); + }); + + afterEach(function () { + const strings = document.getElementById('strings'); + strings.parentNode.removeChild(strings); + + const button = document.getElementById('download-primary'); + button.parentNode.removeChild(button); + }); + + it('should should update Windows and macOS download URLs with a custom build link', function () { + SMIDownload.init(); + + const downloadLinksWin = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="win"]' + ) + ); + const downloadLinksMac = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="osx"]' + ) + ); + + downloadLinksWin.every((link) => + expect(link.href).toContain( + '?product=partner-firefox-release-smi-smi-001-stub' + ) + ); + downloadLinksMac.every((link) => + expect(link.href).toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + }); + + it('should should not update Windows URLs that are not visible on landing page', function () { + SMIDownload.init(); + + const downloadLinksWin64 = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="win64"]' + ) + ); + const downloadLinksWinMsi = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="win64-msi"]' + ) + ); + const downloadLinksWinAarch64 = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="win64-aarch64"]' + ) + ); + + downloadLinksWin64.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001-stub' + ) + ); + downloadLinksWinMsi.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + downloadLinksWinAarch64.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + }); + + it('should should not update Linux download URLs with a custom build link', function () { + SMIDownload.init(); + + const downloadLinksLinux = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="linux"]' + ) + ); + const downloadLinksLinux64 = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="linux64"]' + ) + ); + + downloadLinksLinux.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + downloadLinksLinux64.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + }); + + it('should should not update iOS download URLs with a custom build link', function () { + SMIDownload.init(); + + const downloadLinksIOS = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="ios"]' + ) + ); + + downloadLinksIOS.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + }); + + it('should should not update Android download URLs with a custom build link', function () { + SMIDownload.init(); + + const downloadLinksAndroid = Array.from( + document.querySelectorAll( + '.download-button .download-list .download-link[data-download-version="android"]' + ) + ); + + downloadLinksAndroid.every((link) => + expect(link.href).not.toContain( + '?product=partner-firefox-release-smi-smi-001' + ) + ); + }); + }); +});