diff --git a/modules/ftrackIdSystem.js b/modules/ftrackIdSystem.js index 87b62e980979..17e210d53584 100644 --- a/modules/ftrackIdSystem.js +++ b/modules/ftrackIdSystem.js @@ -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 - '; @@ -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); } }; }, diff --git a/src/adloader.js b/src/adloader.js index c73f83f300c2..0b70686842d3 100644 --- a/src/adloader.js +++ b/src/adloader.js @@ -11,7 +11,8 @@ const _approvedLoadExternalJSList = [ 'browsi', 'brandmetrics', 'justtag', - 'akamaidap' + 'akamaidap', + 'ftrackId' ] /** diff --git a/test/spec/modules/ftrackIdSystem_spec.js b/test/spec/modules/ftrackIdSystem_spec.js index a1c49f321a3a..f2b0456a849c 100644 --- a/test/spec/modules/ftrackIdSystem_spec.js +++ b/test/spec/modules/ftrackIdSystem_spec.js @@ -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; @@ -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:`, () => {