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
11
Versions
130
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.4.0-beta.5 to 5.4.0

105

dist/ads-display.js

@@ -175,3 +175,2 @@ import oAds from '@financial-times/ads-legacy-o-ads';

* adUnit: [],
* smartmatch: {}
* }

@@ -200,7 +199,2 @@ */

}
// Move the smartmatch to top level, it's not metadata
if (fd.metadata[page.type].smartmatch) {
fd.smartmatch = fd.metadata[page.type].smartmatch;
delete fd.metadata[page.type].smartmatch;
}
}

@@ -304,23 +298,2 @@ return fd;

}
/**
* Format the smartmatch targeting data for use in ad requests
* @param {Object} smartmatchData - Smartmatch data returned from the ads-api
* @returns {Object} targeting - { smid: 'values' }
*/
function formatSmartmatchData(smartmatchData) {
if (!isPlainObject(smartmatchData)) return;
if (smartmatchData.targeting) {
const {
key,
value
} = smartmatchData.targeting;
if (key === "smid" && typeof value !== "undefined") {
return {
[key]: value
};
}
}
return null;
}
const getUserData = async ({

@@ -409,68 +382,2 @@ user,

const addIframeMessageListener = () => {
window.addEventListener("message", event => {
const {
data = ""
} = 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 {
const parsedMessage = JSON.parse(event.data);
const {
type
} = parsedMessage || {};
if (!type) {
return;
}
// Log oAdsEmbed monitoring event
if (type === "oAdsEmbed.monitor") {
const payload = {
category: "ads",
action: "embed",
message: parsedMessage.message || ""
};
broadcast("oTracking.event", payload);
return;
}
// 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
// the oAdsEmbed.listens postMessage. We only send our response to it
if (iframe) {
const matches = window.smartmatchCreativeMatches;
if (matches) {
const message = {
messageType: "oAdsEmbed",
body: {
smartmatchCreativeMatches: matches
}
};
iframe.postMessage(message, "*");
}
}
}
} catch (err) {
// Do nothing. If event.data is not valid JSON, it's just not the message we expect
}
});
};
/**
* Add Smartmatch data to the browser window object.
* @param {Object} smartmatchData - Smartmatch data returned from the ads-api
*/
function addSmartmatchToWindow(smartmatchData) {
if (!isPlainObject(smartmatchData)) {
return;
}
if (smartmatchData.matches) {
window.smartmatchCreativeMatches = smartmatchData.matches;
}
}
let pc;

@@ -589,6 +496,2 @@ const _getPersonalisedConsent = async () => {

};
if (options.smartmatch) {
addSmartmatchToWindow(options.smartmatch);
addIframeMessageListener();
}
if (!options.appName) {

@@ -757,4 +660,3 @@ throw new Error("Error initialising display ads. `options.appName` is required");

enableTestCreatives,
targeting,
smartmatch
targeting
} = options;

@@ -773,4 +675,3 @@

...(targeting && formatUserData(targeting.user)),
...(targeting && formatArticleData(targeting.article)),
...(smartmatch && formatSmartmatchData(smartmatch))
...(targeting && formatArticleData(targeting.article))
};

@@ -910,2 +811,2 @@ if (typeof abTestState === "string") {

export { adsUtils, displayAds, formatArticleData, formatSmartmatchData, formatUserData, getAdsData, hideIframedImagesBelow };
export { adsUtils, displayAds, formatArticleData, formatUserData, getAdsData, hideIframedImagesBelow };

10

package.json

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

"type": "module",
"version": "5.4.0-beta.5",
"version": "5.4.0",
"typings": "./types.d.ts",

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

"dependencies": {
"@financial-times/ads-legacy-o-ads": "^5.4.0-beta.5",
"@financial-times/ads-moat-integration": "^5.4.0-beta.5",
"@financial-times/ads-permutive": "^5.4.0-beta.5",
"@financial-times/ads-personalised-consent": "^5.4.0-beta.5",
"@financial-times/ads-legacy-o-ads": "^5.4.0",
"@financial-times/ads-moat-integration": "^5.4.0",
"@financial-times/ads-permutive": "^5.4.0",
"@financial-times/ads-personalised-consent": "^5.4.0",
"@financial-times/n-tracking": "^4.0.1",

@@ -25,0 +25,0 @@ "@financial-times/o-tracking": "^4.0.0",

@@ -184,3 +184,2 @@ # @financial-times/ads-display [![CircleCI](https://circleci.com/gh/Financial-Times/advertising/tree/main.svg?style=svg&circle_token=5a48f4de4ed42fc9fdbe1306eef6b9aae3c66008)](https://circleci.com/gh/Financial-Times/advertising/tree/main)

adUnit: adsData.adUnit, // for article or stream pages
smartmatch: adsData.smartmatch // for article pages
};

@@ -224,3 +223,2 @@ displayAds.init(options, flagsClient);

adUnit: adsData.adUnit,
smartmatch: adsData.smartmatch
}, flagsClient);

@@ -367,3 +365,2 @@

adUnit: [] // ad unit for stream or article pages,
smartmatch: {} // smartmatch object for article pages (if available)
}

@@ -421,24 +418,2 @@ ```

## `formatSmartmatchData(articleData)`
Format the smartmatch data as key => value pairs for use in ad requests. The keys are mapped from the ads-api /v2/user response to the equivalent keys that the ad ops server expects in the ad calls.
### Import
`import { formatSmartmatchData } from '@financial-times/ads-display`
or to minimize bunle size (depending on your build config), you can import directly:
**ES Module:** `import { formatSmartmatchData } from '@financial-times/ads-display/dist/esm/adsData`
**CommonJS:** `import { formatSmartmatchData } from '@financial-times/ads-display/dist/cjs/adsData`
### Usage
```js
getAdsData({...}).then(adsData => {
const keyValuePairs = formatSmartmatchData(adsData.smartmatch);
...
})
```
## `adsPermutive`

@@ -445,0 +420,0 @@

@@ -11,3 +11,2 @@ export type OAdsMetricPayload = {

export declare function formatArticleData(article: Object): Object;
export declare function formatSmartmatchData(smartmatchData: Object): Object;
export declare function formatUserData(user: Object): Object;

@@ -14,0 +13,0 @@ export declare namespace adsUtils {

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