Skip to content
Open
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
11 changes: 8 additions & 3 deletions modules/anonymisedRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,20 @@ export function createRtdProvider(moduleName) {
return;
}
logMessage(`${SUBMODULE_NAME}RtdProvider: Loading Marketing Tag`);
// Check if the script is already loaded
if (document.querySelector(`script[src*="${config.params.tagUrl ?? MARKETING_TAG_URL}"]`)) {
let tagBaseUrl = MARKETING_TAG_URL;
if (config.params?.tagUrl) {
logWarn(`${SUBMODULE_NAME}RtdProvider: params.tagUrl is deprecated and will be removed in a future release.`);
tagBaseUrl = config.params.tagUrl;
}
// Check if the script is already loaded (match on host/path only to handle http://, https://, and protocol-relative URLs)
if (document.querySelector(`script[src*="${tagBaseUrl.replace(/^https?:\/\//, '')}"]`)) {
logMessage(`${SUBMODULE_NAME}RtdProvider: Marketing Tag already loaded`);
return;
}
const tagConfig = config.params?.tagConfig ? { ...config.params.tagConfig, idw_client_id: config.params.tagConfig.clientId } : {};
delete tagConfig.clientId;

const tagUrl = config.params.tagUrl ? config.params.tagUrl : `${MARKETING_TAG_URL}?ref=prebid&d=${window.location.hostname}`;
const tagUrl = `${tagBaseUrl}?ref=prebid&d=${window.location.hostname}`;

loadExternalScript(tagUrl, MODULE_TYPE_RTD, SUBMODULE_NAME, () => {
logMessage(`${SUBMODULE_NAME}RtdProvider: Marketing Tag loaded successfully`);
Expand Down
2 changes: 1 addition & 1 deletion modules/anonymisedRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Anonymised’s Real-time Data Provider automatically obtains segment IDs from th
| params.bidders | `Array` | Bidders with which to share segment information | Optional |
| params.segtax | `Integer` | The taxonomy for Anonymised | '1000' always |
| params.tagConfig | `Object` | Configuration for the Anonymised Marketing Tag | Optional. Defaults to `{}`. |
| params.tagUrl | `String` | The URL of the Anonymised Marketing Tag script | Optional. Defaults to `https://static.anonymised.io/light/loader.js`. |
| params.tagUrl | `String` | The URL of the Anonymised Marketing Tag script | **Deprecated.** Will be removed in a future release. Defaults to `https://static.anonymised.io/light/loader.js`. |

The `anonymisedRtdProvider` must be integrated into the publisher's website along with the [Anonymised Marketing Tag](https://support.anonymised.io/integrate/marketing-tag?t=LPukVCXzSIcRoal5jggyeg). One way to install the Marketing Tag is through `anonymisedRtdProvider` by specifying the required [parameters](https://support.anonymised.io/integrate/optional-anonymised-tag-parameters?t=LPukVCXzSIcRoal5jggyeg) in the `tagConfig` object.

Expand Down
42 changes: 40 additions & 2 deletions test/spec/modules/anonymisedRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ describe('anonymisedRtdProvider', function() {
});

describe('anonymisedRtdSubmodule', function() {
let logWarnStub;
beforeEach(function () {
logWarnStub = sinon.stub(require('src/utils.js'), 'logWarn');
});
afterEach(function () {
logWarnStub.restore();
document.querySelectorAll('script[src*="static.anonymised.io"], script[src*="example.io"]').forEach(s => s.parentNode.removeChild(s));
});

it('successfully instantiates', function () {
expect(anonymisedRtdSubmodule.init()).to.equal(true);
});
Expand Down Expand Up @@ -115,7 +124,35 @@ describe('anonymisedRtdProvider', function() {
anonymisedRtdSubmodule.init(rtdConfig, {});
expect(loadExternalScriptStub.called).to.be.false;
});
it('should load external script from tagUrl when it is set', function () {
it('should not load external script when it is already loaded via http://', function () {
const rtdConfig = {
params: {
tagConfig: {
clientId: 'testId'
}
}
};
const script = document.createElement('script');
script.src = 'http://static.anonymised.io/light/loader.js';
document.body.appendChild(script);
anonymisedRtdSubmodule.init(rtdConfig, {});
expect(loadExternalScriptStub.called).to.be.false;
});
it('should not load external script when it is already loaded via protocol-relative URL', function () {
const rtdConfig = {
params: {
tagConfig: {
clientId: 'testId'
}
}
};
const script = document.createElement('script');
script.src = '//static.anonymised.io/light/loader.js';
document.body.appendChild(script);
anonymisedRtdSubmodule.init(rtdConfig, {});
expect(loadExternalScriptStub.called).to.be.false;
});
it('should load external script from tagUrl when set and log a deprecation warning', function () {
const rtdConfig = {
params: {
tagUrl: 'https://example.io/loader.js',
Expand All @@ -125,9 +162,10 @@ describe('anonymisedRtdProvider', function() {
}
};
anonymisedRtdSubmodule.init(rtdConfig, {});
const expected = 'https://example.io/loader.js';
const expected = `https://example.io/loader.js?ref=prebid&d=${window.location.hostname}`;

expect(loadExternalScriptStub.args[0][0]).to.deep.equal(expected);
expect(logWarnStub.calledWithMatch('params.tagUrl is deprecated')).to.be.true;
});
it('should not load external script from tagUrl when it is already loaded', function () {
const rtdConfig = {
Expand Down
Loading