Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftrack Id Module: replace native appendChild with Prebid's loadExternalScript #8432

Merged
merged 5 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions modules/ftrackIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as utils from '../src/utils.js';
import { submodule } from '../src/hook.js';
import { getStorageManager } from '../src/storageManager.js';
import { uspDataHandler } from '../src/adapterManager.js';
import { loadExternalScript } from '../src/adloader.js';

const MODULE_NAME = 'ftrackId';
const LOG_PREFIX = 'FTRACK - ';
Expand Down Expand Up @@ -101,11 +102,8 @@ export const ftrackIdSubmodule = {
}
}

if (config.params && config.params.url) {
var ftrackScript = document.createElement('script');
ftrackScript.setAttribute('src', config.params.url);
window.document.body.appendChild(ftrackScript);
}
// Creates an async script element and appends it to the document
loadExternalScript(config.params.url, MODULE_NAME);
}
};
},
Expand Down
3 changes: 2 additions & 1 deletion src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const _approvedLoadExternalJSList = [
'browsi',
'brandmetrics',
'justtag',
'akamaidap'
'akamaidap',
'ftrackId'
]

/**
Expand Down
23 changes: 10 additions & 13 deletions test/spec/modules/ftrackIdSystem_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ftrackIdSubmodule } from 'modules/ftrackIdSystem.js';
import * as utils from 'src/utils.js';
import { uspDataHandler } from 'src/adapterManager.js';
import { loadExternalScript } from 'src/adloader.js';
let expect = require('chai').expect;

let server;
Expand Down Expand Up @@ -146,25 +147,21 @@ describe('FTRACK ID System', () => {
});

it(`should be the only method that gets a new ID aka hits the D9 endpoint`, () => {
let appendChildStub = sinon.stub(window.document.body, 'appendChild');

ftrackIdSubmodule.getId(configMock, null, null).callback();
expect(window.document.body.appendChild.called).to.be.ok;
let actualScriptTag = window.document.body.appendChild.args[0][0];
expect(actualScriptTag.tagName.toLowerCase()).to.equal('script');
expect(actualScriptTag.getAttribute('src')).to.equal('https://d9.flashtalking.com/d9core');
appendChildStub.resetHistory();
expect(loadExternalScript.called).to.be.ok;
expect(loadExternalScript.args[0][0]).to.deep.equal('https://d9.flashtalking.com/d9core');
loadExternalScript.resetHistory();

ftrackIdSubmodule.decode('value', configMock);
expect(window.document.body.appendChild.called).to.not.be.ok;
expect(window.document.body.appendChild.args).to.deep.equal([]);
appendChildStub.resetHistory();
expect(loadExternalScript.called).to.not.be.ok;
expect(loadExternalScript.args).to.deep.equal([]);
loadExternalScript.resetHistory();

ftrackIdSubmodule.extendId(configMock, null, {cache: {id: ''}});
expect(window.document.body.appendChild.called).to.not.be.ok;
expect(window.document.body.appendChild.args).to.deep.equal([]);
expect(loadExternalScript.called).to.not.be.ok;
expect(loadExternalScript.args).to.deep.equal([]);

appendChildStub.restore();
loadExternalScript.restore();
});

describe(`should use the "ids" setting in the config:`, () => {
Expand Down