From 9d9d9f8ed0a567c7b27b647cdde123cffc88a59f Mon Sep 17 00:00:00 2001 From: adskeeperdev <81370897+adskeeperdev@users.noreply.github.com> Date: Wed, 31 Jul 2024 20:50:39 +0300 Subject: [PATCH] Adskeeper website attribute (#40045) --- ads/vendors/adskeeper.js | 69 +++++++++++++++++++++++------------- ads/vendors/adskeeper.md | 20 ++++++++++- examples/amp-ad/ads.amp.html | 3 +- 3 files changed, 64 insertions(+), 28 deletions(-) diff --git a/ads/vendors/adskeeper.js b/ads/vendors/adskeeper.js index 116458c17235..13773f424816 100644 --- a/ads/vendors/adskeeper.js +++ b/ads/vendors/adskeeper.js @@ -21,41 +21,60 @@ import {loadScript, validateData} from '#3p/3p'; * @param {!Object} data */ export function adskeeper(global, data) { - validateData(data, ['publisher', 'widget', 'container'], ['url', 'options']); - - const scriptRoot = global.document.createElement('div'); - scriptRoot.id = data.container; - - global.document.body.appendChild(scriptRoot); - - /** - * Returns path for provided js filename - * @param {string} publisher js filename - * @return {string} Path to provided filename. - */ - function getResourceFilePath(publisher) { - const publisherStr = publisher.replace(/[^a-zA-Z0-9]/g, ''); - return `${publisherStr[0]}/${publisherStr[1]}`; - } - - const url = - `https://jsc.adskeeper.com/${getResourceFilePath(data.publisher)}/` + - `${encodeURIComponent(data.publisher)}.` + - `${encodeURIComponent(data.widget)}.js`; + validateData( + data, + [['publisher', 'website'], ['container', 'website'], 'widget'], + ['url', 'options'] + ); global.uniqId = ( '00000' + Math.round(Math.random() * 100000).toString(16) ).slice(-5); - global['ampOptions' + data.widget + '_' + global.uniqId] = data.options; + window['ampOptions' + data.widget + '_' + global.uniqId] = data.options; global.context.observeIntersection(function (changes) { /** @type {!Array} */ (changes).forEach(function (c) { - global['intersectionRect' + data.widget + '_' + global.uniqId] = + window['intersectionRect' + data.widget + '_' + global.uniqId] = c.intersectionRect; - global['boundingClientRect' + data.widget + '_' + global.uniqId] = + window['boundingClientRect' + data.widget + '_' + global.uniqId] = c.boundingClientRect; }); }); - loadScript(global, data.url || url); + if (data.website) { + const widgetContainer = document.createElement('div'); + widgetContainer.dataset.type = '_mgwidget'; + widgetContainer.dataset.widgetId = data.widget; + document.body.appendChild(widgetContainer); + + const url = + `https://jsc.adskeeper.com/site/` + + `${encodeURIComponent(data.website)}.js?t=` + + Math.floor(Date.now() / 36e5); + + loadScript(global, data.url || url); + } else { + const scriptRoot = document.createElement('div'); + scriptRoot.id = data.container; + + document.body.appendChild(scriptRoot); + + /** + * Returns path for provided js filename + * @param {string} publisher js filename + * @return {string} Path to provided filename. + */ + function getResourceFilePath(publisher) { + const publisherStr = publisher.replace(/[^a-zA-Z0-9]/g, ''); + return `${publisherStr[0]}/${publisherStr[1]}`; + } + + const url = + `https://jsc.adskeeper.com/${getResourceFilePath(data.publisher)}/` + + `${encodeURIComponent(data.publisher)}.` + + `${encodeURIComponent(data.widget)}.js?t=` + + Math.floor(Date.now() / 36e5); + + loadScript(global, data.url || url); + } } diff --git a/ads/vendors/adskeeper.md b/ads/vendors/adskeeper.md index 4e292fc80387..a15e7f4a42f5 100644 --- a/ads/vendors/adskeeper.md +++ b/ads/vendors/adskeeper.md @@ -20,6 +20,19 @@ limitations under the License. ### Basic +Latest version: +```html + + +``` + +Legacy version: ```html AdServSolutions

AdsKeeper

- +

AdsLoom