Skip to content

Commit

Permalink
Ftrack Id Module: replace native appendChild with Prebid's loadExtern…
Browse files Browse the repository at this point in the history
…alScript (#8432)

* JDB-533: replacing appendChild in the ftrack prebid module

* JDB-533: working on switching over to AJAX/CDN

* JDB-533: removing some commented out code

* JDB-533: removing redundant conditions

Co-authored-by: Jason Lydon <[email protected]>
  • Loading branch information
ftxmoJason and Jason Lydon authored May 26, 2022
1 parent 90af31d commit ac47d81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
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

0 comments on commit ac47d81

Please sign in to comment.