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

airgridRtdProvider: use provided tag insertion method loadExternalScript #9901

Merged
merged 16 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
43 changes: 19 additions & 24 deletions modules/airgridRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import { submodule } from '../src/hook.js';
import {
deepSetValue,
deepAccess,
mergeDeep,
} from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';
import {getStorageManager} from '../src/storageManager.js';
import {MODULE_TYPE_RTD} from '../src/activities/modules.js';
import { getStorageManager } from '../src/storageManager.js';
import { loadExternalScript } from '../src/adloader.js';
import { MODULE_TYPE_RTD } from '../src/activities/modules.js';

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

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

/**
* Attach script tag to DOM
* @param {Object} rtdConfig
Expand All @@ -33,19 +40,12 @@ 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);
edktInitializor.invoked = true;
const moduleSrc = getModuleUrl(rtdConfig.params.accountId);
loadExternalScript(moduleSrc, SUBMODULE_NAME);
}
}

Expand Down Expand Up @@ -85,24 +85,19 @@ function setAudiencesToAppNexusAdUnits(adUnits, audiences) {
* @param {Array} audiences
* @return {{}} a map from bidder code to ORTB2 config
*/
export function setAudiencesAsBidderOrtb2(rtdConfig, audiences) {
export function getAudiencesAsBidderOrtb2(rtdConfig, audiences) {
const bidders = deepAccess(rtdConfig, 'params.bidders');
if (!bidders || bidders.length === 0 || !audiences || audiences.length === 0) return;

const agOrtb2 = {}
deepSetValue(agOrtb2, 'ortb2.user.ext.data.airgrid', audiences);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is out of spec - data should be an array, sorry for not catching this earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I saw it and missed anyway...
Thank you for the catch! Let me fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, sorry about the confusion @dgirardi, but we're using user.ext.data here, not user.data, which is an array.
Should we be using user.data instead?
I saw it was present here as an obj and we were using it also in the previous implementation, but I'm not sure anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user.ext.data is the safer choice, it has been "promoted" to user.data in ORTB version 2.6 but afaik that hasn't been widely adopted yet.

Copy link
Contributor Author

@naripok naripok May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!
Does this mean that we're good, then? 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection to forking the PR, but I'd prefer then if you rolled this back to just the loadExternalScript change so that the incorrect values in user.ext are not forgotten.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgirardi, I've reverted the data setting changes so this PR includes only the loadExternalScript changes.

Now, for the data setting method, as per last feedback, I understand that the changes introduced in this PR are bad, and we should revert those to the previous setting method, right?
I'm just a little bit confused with all the back and forth we had, so, I'm sorry to ask, but could you please again be very specific in which should be the desired data setting method you'd like to see for the next PR?
Is this the preferred way to go forward?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method is the one you just had in the previous commit, with the difference that the data should be formatted as a ORTB user.data segment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, alright, got ya!
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dgirardi, I've pushed the data setting changes to a PR in our fork here. I'll open a PR here once I know it is good and we have this PR merged.
Would you mind checking out the question in this comment, please?
I'm doing some guesswork there, and it would be great to have some confirmation that I'm getting it right.
Thank you very much!


const keywords = audiences.map(
(audienceId) => `perid=${audienceId}`
).join(',');
deepSetValue(agOrtb2, 'ortb2.user.keywords', keywords);

config.mergeBidderConfig({
bidders: bidders,
config: {
ortb2: {
site: {
keywords,
}
}
}
})
return Object.fromEntries(bidders.map(bidder => [bidder, agOrtb2]));
}

export function setAudiencesUsingAppNexusAuctionKeywords(audiences) {
Expand Down Expand Up @@ -142,7 +137,7 @@ export function passAudiencesToBidders(
const audiences = getMatchedAudiencesFromStorage();
if (audiences.length > 0) {
setAudiencesUsingAppNexusAuctionKeywords(audiences);
setAudiencesAsBidderOrtb2(rtdConfig, audiences)
mergeDeep(bidConfig?.ortb2Fragments?.bidder, getAudiencesAsBidderOrtb2(rtdConfig, audiences));
if (adUnits) {
setAudiencesToAppNexusAdUnits(adUnits, audiences);
}
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