Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/ads-display

Package Overview
Dependencies
Maintainers
10
Versions
131
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/ads-display - npm Package Compare versions

Comparing version 5.3.0 to 5.3.1

216

dist/ads-display.js

@@ -14,6 +14,6 @@ import oAds from '@financial-times/ads-legacy-o-ads';

*/
const isPlainObject = o => {
return typeof o == "object" && o.constructor == Object;
};
/**

@@ -23,6 +23,4 @@ * Search a cookie string for user data and return it

*/
const setDefaultUserDataFromCookie = cookie => {
var _cookie$match;
const spoorId = ((_cookie$match = cookie.match("(^|;)\\s*" + "spoor-id" + "\\s*=\\s*([^;]+)")) === null || _cookie$match === void 0 ? void 0 : _cookie$match.pop()) || false;

@@ -35,2 +33,3 @@ return {

};
/**

@@ -51,3 +50,2 @@ * Returns the margin to apply to the viewport as a percentage string given an object of sizes

*/
const calculateViewportMargin = ({

@@ -60,8 +58,9 @@ breakpointMargins,

return fallbackValue;
} // Find the size that is just higher than the viewportsize
}
// Find the size that is just higher than the viewportsize
const nextHighestBreakpointKey = Object.keys(breakpointMargins).sort().find(a => +a > viewportSize);
return breakpointMargins[nextHighestBreakpointKey] || fallbackValue;
};
/**

@@ -71,6 +70,4 @@ * Create a performance mark in the browser

*/
const perfMark = name => {
const performance = window.LUX || window.performance;
if (performance && performance.mark) {

@@ -81,2 +78,3 @@ performance.clearMarks(name);

};
/**

@@ -91,3 +89,2 @@ * Use postMessage to address issue of media queries not applying to framed content

*/
function hideIframedImagesBelow(collapseBelow = 740) {

@@ -105,6 +102,5 @@ /**

const adFrameSelector = `iframe[src^="${targetOrigin}"][data-load-complete="true"]`;
/** @type {NodeListOf<HTMLIFrameElement>} */
const iframes = document.querySelectorAll(adFrameSelector);
for (const iframe of iframes) {

@@ -118,5 +114,5 @@ if (iframe.contentWindow) {

}
} // @ts-ignore
}
// @ts-ignore
document.body.addEventListener("oViewport.resize", onResize);

@@ -128,3 +124,2 @@ oViewport.listenTo("resize");

const DEFAULT_ADS_API_HOST = "https://ads-api.ft.com/v2";
function getEndpointFromPageType(pageType) {

@@ -134,9 +129,8 @@ if (pageType === "article") {

}
if (pageType === "stream") {
return "concept";
}
return undefined;
}
/**

@@ -147,13 +141,8 @@ * Fetch data from the ads-api /content or /concept endpoints

*/
async function fetchPageData(host, endpoint, pageId) {
if (!pageId || !endpoint.match(/^(content|concept)$/)) {
console.error("Invalid ads-api endpoint specified for retrieving page targeting data"); //eslint-disable-line no-console
return;
}
const url = `${host}/${endpoint}/${pageId}`;
try {

@@ -169,10 +158,8 @@ const resp = await fetch(url, {

}
/**
* Fetch data from the ads-api /user endpoint
*/
async function fetchUserData(host) {
const url = `${host}/user`;
try {

@@ -189,2 +176,3 @@ const resp = await fetch(url, {

}
/**

@@ -205,4 +193,2 @@ * Format the ads-api response into something a bit more useful

*/
function formatAdsApiData(data, page) {

@@ -212,20 +198,20 @@ // Formatted data

metadata: {}
}; // We have user data
};
// We have user data
if (data.length >= 1) {
fd.metadata.user = { ...(isPlainObject(data[0]) && data[0])
fd.metadata.user = {
...(isPlainObject(data[0]) && data[0])
};
} // We also have page data
}
// We also have page data
if (data.length === 2 && isPlainObject(page)) {
fd.metadata[page.type] = { ...(isPlainObject(data[1]) && data[1])
}; // Move the ad unit to top level, it's not metadata
fd.metadata[page.type] = {
...(isPlainObject(data[1]) && data[1])
};
// Move the ad unit to top level, it's not metadata
if (fd.metadata[page.type].adUnit) {
fd.adUnit = fd.metadata[page.type].adUnit;
delete fd.metadata[page.type].adUnit;
} // Move the smartmatch to top level, it's not metadata
}
// Move the smartmatch to top level, it's not metadata
if (fd.metadata[page.type].smartmatch) {

@@ -236,5 +222,5 @@ fd.smartmatch = fd.metadata[page.type].smartmatch;

}
return fd;
}
/**

@@ -246,4 +232,2 @@ * Format the user data as key => value pairs for use in ad requests

*/
function formatUserData(user) {

@@ -256,6 +240,8 @@ if (isPlainObject(user)) {

const hasResponsibility = user.responsibility && user.responsibility.code;
const hasPosition = user.position && user.position.code; // E.g. if `user.uuid` evaluates truthly, destruct the object
const hasPosition = user.position && user.position.code;
// E.g. if `user.uuid` evaluates truthly, destruct the object
// { guid: user:uuid }
return { ...(user.uuid && {
return {
...(user.uuid && {
guid: user.uuid

@@ -289,3 +275,2 @@ }),

}) // weird number mapping. 07 = position
};

@@ -296,2 +281,3 @@ }

}
/**

@@ -303,9 +289,10 @@ * Format the page targeting data as key => value pairs for use in ad requests

*/
function formatArticleData(article) {
if (isPlainObject(article)) {
const hasSpecialReport = Array.isArray(article.specialReport) && article.specialReport.length > 0; // E.g. if `page.uuid` evaluates truthly, destruct the object
const hasSpecialReport = Array.isArray(article.specialReport) && article.specialReport.length > 0;
// E.g. if `page.uuid` evaluates truthly, destruct the object
// { auuid: page:uuid }
return { ...(article.uuid && {
return {
...(article.uuid && {
auuid: article.uuid

@@ -336,5 +323,5 @@ }),

}
return null;
}
/**

@@ -345,6 +332,4 @@ * Format the smartmatch targeting data for use in ad requests

*/
function formatSmartmatchData(smartmatchData) {
if (!isPlainObject(smartmatchData)) return;
if (smartmatchData.targeting) {

@@ -355,3 +340,2 @@ const {

} = smartmatchData.targeting;
if (key === "smid" && typeof value !== "undefined") {

@@ -363,3 +347,2 @@ return {

}
return null;

@@ -384,2 +367,3 @@ }

};
/**

@@ -407,3 +391,2 @@ * Fetch targeting data

*/
async function getAdsData({

@@ -427,11 +410,10 @@ user = false,

}
return settledResult.value;
});
perfMark("oAds.adsAPIComplete"); // If the user data has not populated correctly, try to get it from cookie
perfMark("oAds.adsAPIComplete");
// If the user data has not populated correctly, try to get it from cookie
if (adsApiResponses[0] == undefined || !adsApiResponses[0].spoorId && document.cookie) {
adsApiResponses[0] = setDefaultUserDataFromCookie(document.cookie);
}
return formatAdsApiData(adsApiResponses, page);

@@ -443,3 +425,2 @@ }

let data = {};
if (adsConfigEl) {

@@ -460,8 +441,7 @@ try {

data = ""
} = event; // We don't want to waste time trying to parse postMessage that we know aren't for us
} = event;
// We don't want to waste time trying to parse postMessage that we know aren't for us
if (typeof data !== "string" || !data.match(/oAds/)) {
return;
}
try {

@@ -472,8 +452,7 @@ const parsedMessage = JSON.parse(event.data);

} = parsedMessage || {};
if (!type) {
return;
} // Log oAdsEmbed monitoring event
}
// Log oAdsEmbed monitoring event
if (type === "oAdsEmbed.monitor") {

@@ -487,12 +466,11 @@ const payload = {

return;
} // Pass data to iframe when iframe signals readiness to receive it
}
// Pass data to iframe when iframe signals readiness to receive it
if (type === "oAdsEmbed.listens") {
const iframe = event.source; // 'iframe' is a reference to the specific iframe that sent
const iframe = event.source;
// 'iframe' is a reference to the specific iframe that sent
// the oAdsEmbed.listens postMessage. We only send our response to it
if (iframe) {
const matches = window.smartmatchCreativeMatches;
if (matches) {

@@ -509,3 +487,4 @@ const message = {

}
} catch (err) {// Do nothing. If event.data is not valid JSON, it's just not the message we expect
} catch (err) {
// Do nothing. If event.data is not valid JSON, it's just not the message we expect
}

@@ -519,3 +498,2 @@ });

*/
function addSmartmatchToWindow(smartmatchData) {

@@ -525,3 +503,2 @@ if (!isPlainObject(smartmatchData)) {

}
if (smartmatchData.matches) {

@@ -533,3 +510,2 @@ window.smartmatchCreativeMatches = smartmatchData.matches;

let pc;
const _getPersonalisedConsent = async () => {

@@ -543,3 +519,2 @@ if (!pc) {

}
return pc;

@@ -556,8 +531,9 @@ };

*/
// Probability that a page view is chosen to be send ads-related metrics
// This sampling is ignored by `setupMetrics` if the `ignoreSampling`
// parameter is true
const METRICS_SAMPLE_SIZE = 0.1;
const METRICS_SAMPLE_SIZE = 0.1; // Update the documentation if an event gets added
// Update the documentation if an event gets added
const metricsDefinitions = [{

@@ -597,6 +573,8 @@ sampleSize: METRICS_SAMPLE_SIZE,

const allowedAdsTypes = await pc.isAllowed();
return { ...allowedAdsTypes,
return {
...allowedAdsTypes,
gpcValue: pc.getGpcValue()
};
};
/**

@@ -609,3 +587,2 @@ * Set up the ad events to record according to the metrics definition object,

*/
function setupMetrics(ignoreSampling) {

@@ -620,12 +597,10 @@ /**

consents.usprivacy = uscookie;
if (payload) {
payload.advert = { ...payload.advert,
payload.advert = {
...payload.advert,
consents
};
}
return broadcast("oTracking.event", payload);
};
oAds.utils.setupMetrics(metricsDefinitions, callback, ignoreSampling);

@@ -636,2 +611,3 @@ }

let oAdsDeviceSpoorId = "";
/**

@@ -642,7 +618,6 @@ * Initialise display ads via o-ads

*/
async function init(options, flags) {
var _pc$isAllowed;
options = { ...getEmbeddedOptions(),
options = {
...getEmbeddedOptions(),
...options,

@@ -652,3 +627,2 @@ //if adsEnableTestCreatives flag is set, pass sandbox as true downstream, as that's checked to show test creatives

};
if (options.smartmatch) {

@@ -658,21 +632,15 @@ addSmartmatchToWindow(options.smartmatch);

}
if (!options.appName) {
throw new Error("Error initialising display ads. `options.appName` is required");
}
if (!options.disableMonitoring) {
setupMetrics(true);
}
setUSPrivacy();
const oAdsInstance = await displayAds.initOads(options, flags);
if (options.waitForMoat) {
moatIntegration();
}
displayAds.initAdSlots(oAdsInstance);
const pc = await _getPersonalisedConsent();
if (pc !== null && pc !== void 0 && (_pc$isAllowed = pc.isAllowed()) !== null && _pc$isAllowed !== void 0 && _pc$isAllowed.all || flags.get("adsDisableInternalCMP")) {

@@ -682,2 +650,3 @@ displayAds.pushGooglePpid(oAdsDeviceSpoorId);

}
/**

@@ -687,15 +656,11 @@ * Scan and initialise all ad slots on the page

*/
function initAdSlots(oAdsInstance) {
const containers = document.querySelectorAll(".o-ads, [data-o-ads-name]");
if (!containers.length) {
console.warn("No ad slot found on the page"); // eslint-disable-line no-console
return;
}
containers.forEach(container => oAdsInstance.slots.initSlot(container));
}
/**

@@ -706,7 +671,4 @@ * Initialise oAds and return instance

*/
async function initOads(options, flags) {
let oAdsInstance;
try {

@@ -721,2 +683,3 @@ const oAdsConfig = displayAds.getOAdsConfig(options, flags);

}
/**

@@ -726,4 +689,2 @@ * Initialise Google Publisher Provided ID

*/
function pushGooglePpid(deviceSpoorId) {

@@ -737,2 +698,3 @@ if (deviceSpoorId) {

}
/**

@@ -742,26 +704,20 @@ * Returns the gpt.site oAds configuration option

*/
function getGptSite(sandbox) {
if (sandbox) {
console.warn("o-ads running in sandbox mode. No live ads showing"); // eslint-disable-line no-console
return "test.5887.origami";
}
if (location.hash.includes("adsandbox")) {
console.warn("o-ads running in sandbox mode. No live ads showing"); // eslint-disable-line no-console
return "sandbox.next.ft";
} // Setting up an ad unit that doesn't contain the moat wrapper to gauge its impact
}
// Setting up an ad unit that doesn't contain the moat wrapper to gauge its impact
if (location.hash.includes("moatwrappertest")) {
console.warn("o-ads running in sandbox mode. No live ads showing"); // eslint-disable-line no-console
return "test.5887.moatperformance";
}
return "ft.com";
}
/**

@@ -771,7 +727,6 @@ * Return the ad unit as a string for the gpt.zone oAds configuration option

*/
function getGptZone(adUnit) {
return Array.isArray(adUnit) ? adUnit.join("/") : "unclassified";
}
/**

@@ -782,4 +737,2 @@ * Create a configuration object for oAds from options and flags

*/
function getOAdsConfig(options) {

@@ -816,4 +769,4 @@ const {

...options.formats // custom formats
},
},
responsive: {

@@ -827,4 +780,4 @@ extra: [1025, 0],

small: [0, 0] // Mobile
},
},
collapseEmpty: "before",

@@ -841,2 +794,3 @@ lazyLoad: {

}
/**

@@ -847,4 +801,2 @@ * Return an object of key => value pairs that will be used by oAds to append

*/
const getAllTargeting = options => {

@@ -859,5 +811,6 @@ const {

smartmatch
} = options; // TODO: Find out if values need to be URL encoded or
} = options;
// TODO: Find out if values need to be URL encoded or
// if o-ads/gpt does this as part of targeting.add
const oAdsTargeting = {

@@ -875,7 +828,5 @@ pt: appName.toLowerCase().substr(0, 3),

};
if (typeof abTestState === "string") {
const abTestStateObj = Object.fromEntries(abTestState.split(",").map(kv => kv.split(":")));
const mvt2 = abTestStateObj.AdsCommercialMvt2AB;
if (typeof mvt2 === "string" && mvt2.length) {

@@ -885,7 +836,6 @@ oAdsTargeting.mvt2 = mvt2;

}
return oAdsTargeting;
}; // Necessary for testing
};
// Necessary for testing
const displayAds = {

@@ -913,3 +863,4 @@ init,

(metadata === null || metadata === void 0 ? void 0 : metadata.user) && adsPermutive.identifyUser(metadata.user);
const pageViewData = adsPermutive.fromAdsDataToPageView({ ...metadata,
const pageViewData = adsPermutive.fromAdsDataToPageView({
...metadata,
rootId,

@@ -920,2 +871,3 @@ type

};
/**

@@ -932,3 +884,2 @@ * Helper function for setting up permutive on FT.com

*/
async function enablePermutiveFtCom({

@@ -950,3 +901,2 @@ metadata,

*/
const getPermutiveConsent = (disableInternalCmp, {

@@ -958,5 +908,3 @@ permutiveVendor,

};
const permutiveAllowed = getPermutiveConsent(disableInternalCmp, pc === null || pc === void 0 ? void 0 : pc.isAllowed());
if (permutiveAllowed) {

@@ -970,5 +918,5 @@ setupPermutive({

}
return false;
}
/**

@@ -983,3 +931,2 @@ * Helper function for updating consent information in Personalised Consent

*/
async function updateConsentInfo({

@@ -1015,3 +962,2 @@ updatePrivacyLegislation,

/** @type {HTMLAnchorElement|null} */
const manageCookiesLink = document.querySelector("[data-n-messaging-manage-cookies]");

@@ -1018,0 +964,0 @@ addRedirectToManageCookiesLink(window.location.href, manageCookiesLink);

@@ -5,3 +5,3 @@ {

"type": "module",
"version": "5.3.0",
"version": "5.3.1",
"typings": "./types.d.ts",

@@ -19,10 +19,10 @@ "files": [

"dependencies": {
"@financial-times/ads-legacy-o-ads": "^5.3.0",
"@financial-times/ads-moat-integration": "^5.3.0",
"@financial-times/ads-permutive": "^5.3.0",
"@financial-times/ads-personalised-consent": "^5.3.0",
"@financial-times/ads-legacy-o-ads": "^5.3.1",
"@financial-times/ads-moat-integration": "^5.3.1",
"@financial-times/ads-permutive": "^5.3.1",
"@financial-times/ads-personalised-consent": "^5.3.1",
"@financial-times/n-tracking": "^4.0.1",
"@financial-times/o-tracking": "^4.0.0",
"@financial-times/o-viewport": "^5.1.1",
"@financial-times/privacy-us-privacy": "^1.0.0"
"@financial-times/privacy-us-privacy": "^2.2.1"
},

@@ -29,0 +29,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc