[fix bug 1343033] Add Yahoo tracking pixels to scene2 of /firefox/new/

This commit is contained in:
alexgibson 2017-02-28 10:20:36 +00:00
Родитель 19ca21fe3c
Коммит a7112e0263
12 изменённых файлов: 151 добавлений и 42 удалений

Просмотреть файл

@ -9,7 +9,7 @@
{% block body_class %}scene-2{% endblock %}
{% block string_data %}
data-tracking-pixel={{ settings.TRACKING_PIXEL_URL }}
data-pixels="{% for pixel in settings.TRACKING_PIXELS %}{{ pixel }}{% if not loop.last %}::{% endif %}{% endfor %}"
{% endblock %}
{% block content %}

Просмотреть файл

@ -12,7 +12,7 @@
{% block body_id %}firefox-new-onboarding-scene2{% endblock %}
{% block string_data %}
data-tracking-pixel={{ settings.TRACKING_PIXEL_URL }}
data-pixels="{% for pixel in settings.TRACKING_PIXELS %}{{ pixel }}{% if not loop.last %}::{% endif %}{% endfor %}"
{% endblock %}
{% block content %}

Просмотреть файл

@ -14,7 +14,7 @@
{% block body_id %}firefox-new-scene2{% endblock %}
{% block string_data %}
data-tracking-pixel={{ settings.TRACKING_PIXEL_URL }}
data-pixels="{% for pixel in settings.TRACKING_PIXELS %}{{ pixel }}{% if not loop.last %}::{% endif %}{% endfor %}"
{% endblock %}
{% block content %}

Просмотреть файл

@ -9,7 +9,7 @@
{% block body_class %}scene-2{% endblock %}
{% block string_data %}
data-tracking-pixel={{ settings.TRACKING_PIXEL_URL }}
data-pixels="{% for pixel in settings.TRACKING_PIXELS %}{{ pixel }}{% if not loop.last %}::{% endif %}{% endfor %}"
{% endblock %}
{% block content_body %}

Просмотреть файл

@ -1273,14 +1273,22 @@ if CSP_EXTRA_FRAME_SRC:
# support older browsers (mainly Safari)
CSP_FRAME_SRC = CSP_CHILD_SRC
# Bug 1331069 - Double Click tracking pixel for download page.
TRACKING_PIXEL_URL = ('https://ad.doubleclick.net/ddm/activity/src=6417015;type=deskt0;cat=mozil0;dc_lat=;dc_rdid=;'
'tag_for_child_directed_treatment=;ord=1;num=1?&_dc_ck=try')
# Bug 1331069, 1343033 - Double Click & Yahoo tracking pixels for download page.
AVAILABLE_TRACKING_PIXELS = {
'doubleclick': ('https://ad.doubleclick.net/ddm/activity/src=6417015;type=deskt0;cat=mozil0;dc_lat=;dc_rdid=;'
'tag_for_child_directed_treatment=;ord=1;num=1?&_dc_ck=try'),
'yahoo_purple': 'https://sp.analytics.yahoo.com/spp.pl?a=10000&.yp=10022313',
'yahoo_green': 'https://sp.analytics.yahoo.com/spp.pl?a=10000&.yp=10022314',
}
ENABLED_PIXELS = config('ENABLED_PIXELS', default='doubleclick,yahoo_purple,yahoo_green', cast=Csv())
TRACKING_PIXELS = [AVAILABLE_TRACKING_PIXELS[x] for x in ENABLED_PIXELS if x in AVAILABLE_TRACKING_PIXELS]
if config('SWITCH_TRACKING_PIXEL', default=DEV, cast=bool):
CSP_IMG_SRC += (
'ad.doubleclick.net',
)
if 'doubleclick' in ENABLED_PIXELS:
CSP_IMG_SRC += ('ad.doubleclick.net',)
if any([x.startswith('yahoo') for x in ENABLED_PIXELS]):
CSP_IMG_SRC += ('sp.analytics.yahoo.com',)
# Bug 1340087 - Funnelcake experiments default to Windows 32bit and en-US builds only.
FUNNELCAKE_PLATFORMS = config('FUNNELCAKE_PLATFORMS', default='win', cast=Csv())

Просмотреть файл

@ -1300,7 +1300,8 @@ PIPELINE_JS = {
},
'firefox_new_pixel': {
'source_filenames': (
'js/firefox/new/pixel.js',
'js/base/mozilla-pixel.js',
'js/base/mozilla-pixel-init.js',
),
'output_filename': 'js/firefox_new_pixel-bundle.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 http://mozilla.org/MPL/2.0/. */
(function() {
'use strict';
Mozilla.Pixel.init();
})();

Просмотреть файл

@ -0,0 +1,58 @@
/* 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/. */
// Create namespace
if (typeof Mozilla === 'undefined') {
var Mozilla = {};
}
(function() {
'use strict';
/**
* Tracking pixels for /firefox/new/?scene=2 download page.
* For more info see websites privacy notice and bugs:
* https://www.mozilla.org/privacy/websites/
* Yahoo: bug 1343033.
* Double Click: bug 1331069.
* Pixel switch status: bug 1311423.
*/
var Pixel = {};
Pixel.getPixelData = function() {
return $('#strings').data('pixels');
};
Pixel.setPixels = function() {
var $body = $('body');
var pixels = Pixel.getPixelData();
var $pixel;
if (typeof pixels !== 'string' || pixels === '') {
return;
}
// '::' is a separator for each pixel URL.
pixels = pixels.split('::');
for (var i = 0; i < pixels.length; i++) {
$pixel = $('<img />', {
width: '1',
height: '1',
src: pixels[i].replace(/\s/g, '')
});
$pixel.addClass('moz-px');
$body.append($pixel);
}
};
Pixel.init = function() {
// Do not set pixels if visitor has DNT enabled.
if (!window._dntEnabled()) {
Pixel.setPixels();
}
};
window.Mozilla.Pixel = Pixel;
})();

Просмотреть файл

@ -1,26 +0,0 @@
/* 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/. */
(function() {
'use strict';
// pixel status bug https://bugzilla.mozilla.org/show_bug.cgi?id=1311423
function addPixel() {
if (!window._dntEnabled()) {
var href = $('#strings').data('trackingPixel');
if (href) {
var $pixel = $('<img />', {
width: '1',
height: '1',
src: href
});
$('body').append($pixel);
}
}
}
addPixel();
})();

Просмотреть файл

@ -10,6 +10,7 @@
var $platformLink = $('#download-button-wrapper-desktop .download-list li:visible .download-link');
var downloadURL;
// Only auto-start the download if a visible platform link is detected.
if ($platformLink.length) {
downloadURL = $platformLink.attr('href');
@ -17,12 +18,14 @@
// TODO: Remove and generate link in bedrock.
$directDownloadLink.attr('href', downloadURL);
// if user is not on an IE that blocks JS triggered downloads, start the
// platform-detected download after window (read: images) have loaded.
// only auto-start the download if a visible platform link is detected.
// If user is not on an IE that blocks JS triggered downloads, start the
// platform-detected download a second after DOM ready event. We don't rely on
// the window load event as we have third-party tracking pixels.
if (!isIELT9) {
$(window).on('load', function() {
window.location.href = downloadURL;
$(function() {
setTimeout(function() {
window.location.href = downloadURL;
}, 1000);
});
}
}

Просмотреть файл

@ -24,6 +24,7 @@ module.exports = function(config) {
'media/js/base/mozilla-image-helper.js',
'media/js/base/mozilla-modal.js',
'media/js/base/mozilla-pager.js',
'media/js/base/mozilla-pixel.js',
'media/js/base/mozilla-share-cta.js',
'media/js/base/mozilla-video-poster.js',
'media/js/base/nav-main-resp.js',
@ -53,6 +54,7 @@ module.exports = function(config) {
'tests/unit/spec/base/mozilla-image-helper.js',
'tests/unit/spec/base/mozilla-accordion.js',
'tests/unit/spec/base/mozilla-pager.js',
'tests/unit/spec/base/mozilla-pixel.js',
'tests/unit/spec/base/search-params.js',
'tests/unit/spec/base/mozilla-svg-image-fallback.js',
'tests/unit/spec/firefox/new-ios-redirect-helper.js',

Просмотреть файл

@ -0,0 +1,54 @@
/* For reference read the Jasmine and Sinon docs
* Jasmine docs: https://jasmine.github.io/2.0/introduction.html
* Sinon docs: http://sinonjs.org/docs/
*/
/* global describe, beforeEach, afterEach, it, expect */
describe('mozilla-pixel.js', function() {
'use strict';
afterEach(function() {
$('.moz-px').remove();
});
describe('init', function() {
it('should not add pixel img if "do not track" is enabled', function() {
spyOn(window, '_dntEnabled').and.returnValue(true);
spyOn(Mozilla.Pixel, 'setPixels');
Mozilla.Pixel.init();
expect(Mozilla.Pixel.setPixels).not.toHaveBeenCalled();
});
it('should add multiple pixels to document body', function() {
var pixels = '/img/foo.png::/img/foo.png?v=1::/img/foo.png?v=2';
spyOn(window, '_dntEnabled').and.returnValue(false);
spyOn(Mozilla.Pixel, 'getPixelData').and.returnValue(pixels);
Mozilla.Pixel.init();
expect($('.moz-px').length).toEqual(3);
});
it('should add one pixel to document body', function() {
spyOn(window, '_dntEnabled').and.returnValue(false);
spyOn(Mozilla.Pixel, 'getPixelData').and.returnValue('/img/foo.png');
Mozilla.Pixel.init();
expect($('.moz-px').length).toEqual(1);
});
it('should not add pixel if data is undefined', function() {
spyOn(window, '_dntEnabled').and.returnValue(false);
spyOn(Mozilla.Pixel, 'getPixelData').and.returnValue(undefined);
Mozilla.Pixel.init();
expect($('.moz-px').length).toEqual(0);
});
it('should not add pixel if data is empty', function() {
spyOn(window, '_dntEnabled').and.returnValue(false);
spyOn(Mozilla.Pixel, 'getPixelData').and.returnValue('');
Mozilla.Pixel.init();
expect($('.moz-px').length).toEqual(0);
});
});
});