Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions integrations/criteo/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var pick = require('@ndhoule/pick');
var each = require('@ndhoule/each');
var md5 = require('md5');
var isEmail = require('is-email');
var useHttps = require('use-https');
var is = require('is');

/**
Expand All @@ -30,9 +29,7 @@ var Criteo = (module.exports = integration('Criteo')
.option('account', '')
.option('homeUrl', '')
.option('supportingUserData', {})
.option('supportingPageData', {})
.tag('http', '<script src="http://static.criteo.net/js/ld/ld.js">')
.tag('https', '<script src="https://static.criteo.net/js/ld/ld.js">'));
.option('supportingPageData', {}));

/**
* Initialize.
Expand All @@ -47,8 +44,22 @@ Criteo.prototype.initialize = function() {
window.criteo_q.push({ event: 'setAccount', account: account });
window.criteo_q.push({ event: 'setSiteType', type: getDeviceType() });

var protocol = useHttps() ? 'https' : 'http';
this.load(protocol, this.ready);
this.load(this.ready);
Comment thread
AnkitSegment marked this conversation as resolved.
Outdated
};

/**
* Load the Criteo dynamic loader script into the <head>.
*
* @api private
* @param {Function} done
*/

Criteo.prototype.load = function(done) {
var script = document.createElement('script');
script.src = '//dynamic.criteo.com/js/ld/ld.js?a=' + this.options.account;
script.async = 1;
script.onload = done;
document.getElementsByTagName('head')[0].appendChild(script);
};

/**
Expand Down
5 changes: 2 additions & 3 deletions integrations/criteo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/analytics.js-integration-criteo",
"description": "The Criteo analytics.js integration.",
"version": "1.2.4",
"version": "1.3.0",
"keywords": [
"analytics.js",
"analytics.js-integration",
Expand Down Expand Up @@ -31,8 +31,7 @@
"is": "^3.2.1",
"is-email": "^1.0.1",
"md5": "^2.2.1",
"obj-case": "^0.2.0",
"use-https": "^0.1.1"
"obj-case": "^0.2.0"
},
"devDependencies": {
"@segment/analytics.js-core": "^3.8.2",
Expand Down
9 changes: 8 additions & 1 deletion integrations/criteo/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Criteo', function() {
.option('homeUrl', '')
.option('supportingUserData', {})
.option('supportingPageData', {})
.tag('<script src="http://static.criteo.net/js/ld/ld.js">')
);
});

Expand All @@ -63,6 +62,14 @@ describe('Criteo', function() {
analytics.called(criteo.load);
});

it('should load the dynamic loader script into the head', function() {
criteo.load = Criteo.prototype.load;
analytics.initialize();
var scripts = document.getElementsByTagName('head')[0].querySelectorAll('script[src*="dynamic.criteo.com"]');
analytics.assert(scripts.length > 0);
analytics.assert(scripts[0].src.indexOf('//dynamic.criteo.com/js/ld/ld.js?a=' + options.account) !== -1);
Comment thread
AnkitSegment marked this conversation as resolved.
Outdated
});

it('should track setSiteType for desktop', function() {
analytics.stub(window.criteo_q, 'push');
analytics.initialize();
Expand Down