Skip to content

Commit

Permalink
Merge pull request #2 from AirGrid/chore/1459-use-tag-insertion-method
Browse files Browse the repository at this point in the history
chore: use provided tag insertion method
  • Loading branch information
naripok authored May 3, 2023
2 parents 7b5f106 + 3209565 commit d5e12e6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
26 changes: 13 additions & 13 deletions modules/airgridRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';
import { getStorageManager } from '../src/storageManager.js';
import { loadExternalScript } from '../src/adloader.js';

const MODULE_NAME = 'realTimeData';
const SUBMODULE_NAME = 'airgrid';
Expand All @@ -24,6 +25,11 @@ export const storage = getStorageManager({
moduleName: SUBMODULE_NAME,
});

function getModuleUrl(publisherId) {
const path = publisherId ?? 'sdk';
return `https://cdn.edkt.io/${path}/edgekit.min.js`;
}

/**
* Attach script tag to DOM
* @param {Object} rtdConfig
Expand All @@ -32,19 +38,13 @@ export const storage = getStorageManager({
export function attachScriptTagToDOM(rtdConfig) {
var edktInitializor = (window.edktInitializor = window.edktInitializor || {});
if (!edktInitializor.invoked) {
edktInitializor.invoked = true;
edktInitializor.accountId = rtdConfig.params.accountId;
edktInitializor.publisherId = rtdConfig.params.publisherId;
edktInitializor.apiKey = rtdConfig.params.apiKey;
edktInitializor.load = function (e) {
var p = e || 'sdk';
var n = document.createElement('script');
n.type = 'module';
n.async = true;
n.src = 'https://cdn.edkt.io/' + p + '/edgekit.min.js';
document.getElementsByTagName('head')[0].appendChild(n);
};
edktInitializor.load(edktInitializor.accountId);
const moduleSrc = getModuleUrl(rtdConfig.params.publisherId);
loadExternalScript(moduleSrc, SUBMODULE_NAME, () => {
edktInitializor.invoked = true;
edktInitializor.accountId = rtdConfig.params.accountId;
edktInitializor.publisherId = rtdConfig.params.publisherId;
edktInitializor.apiKey = rtdConfig.params.apiKey;
});
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/adloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const _approvedLoadExternalJSList = [
'improvedigital',
'aaxBlockmeter',
'confiant',
'arcspan'
'arcspan',
'airgrid'
]

/**
Expand Down
2 changes: 2 additions & 0 deletions test/spec/modules/airgridRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { config } from 'src/config.js';
import { deepAccess } from 'src/utils.js';
import { getAdUnits } from '../../fixtures/fixtures.js';
import * as agRTD from 'modules/airgridRtdProvider.js';
import { loadExternalScript } from '../../../src/adloader.js';

const MATCHED_AUDIENCES = ['travel', 'sport'];
const RTD_CONFIG = {
Expand Down Expand Up @@ -40,6 +41,7 @@ describe('airgrid RTD Submodule', function () {
expect(agRTD.airgridSubmodule.init(RTD_CONFIG.dataProviders[0])).to.equal(
true
);
expect(loadExternalScript.called).to.be.true
});

it('should attach script to DOM with correct config', function () {
Expand Down

0 comments on commit d5e12e6

Please sign in to comment.