From d384cbb5c033571ad37fc9bf433086e4994027ba Mon Sep 17 00:00:00 2001 From: velichkin Date: Fri, 9 Aug 2024 05:05:20 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20new=20attribute=20to=20mgid?= =?UTF-8?q?=20and=20idealmedia=20ad=20components=20(#40044)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add website parameter support for mgid and idealmedia * Add website parameter support for mgid and idealmedia * Add website parameter support for mgid and idealmedia * Add website parameter support for mgid and idealmedia --- ads/_a4a-config.js | 4 +- ads/vendors/idealmedia.js | 64 ++++++++++++++++++++------------ ads/vendors/idealmedia.md | 20 +++++++++- ads/vendors/mgid.js | 64 ++++++++++++++++++++------------ ads/vendors/mgid.md | 20 +++++++++- examples/amp-ad/ads.amp.esm.html | 10 ++--- examples/amp-ad/ads.amp.html | 6 +-- 7 files changed, 129 insertions(+), 59 deletions(-) diff --git a/ads/_a4a-config.js b/ads/_a4a-config.js index 91c1c16abe8b..9d7aab2fadea 100644 --- a/ads/_a4a-config.js +++ b/ads/_a4a-config.js @@ -27,7 +27,9 @@ export function getA4ARegistry() { 'dianomi': () => true, 'doubleclick': () => true, 'fake': () => true, - 'mgid': (win, adTag) => !adTag.hasAttribute('data-container'), + 'mgid': (win, adTag) => + !adTag.hasAttribute('data-container') && + !adTag.hasAttribute('data-website'), 'nws': () => true, 'smartadserver': () => true, 'valueimpression': () => true, diff --git a/ads/vendors/idealmedia.js b/ads/vendors/idealmedia.js index a3f4f556287f..f24d97fcde52 100644 --- a/ads/vendors/idealmedia.js +++ b/ads/vendors/idealmedia.js @@ -5,28 +5,11 @@ import {loadScript, validateData} from '#3p/3p'; * @param {!Object} data */ export function idealmedia(global, data) { - validateData(data, ['publisher', 'widget', 'container'], ['url', 'options']); - - const scriptRoot = document.createElement('div'); - scriptRoot.id = data.container; - - document.body.appendChild(scriptRoot); - - /** - * Returns path for provided js filename - * @param {string} publisher The first number. - * @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.idealmedia.io/${getResourceFilePath(data.publisher)}/` + - `${encodeURIComponent(data.publisher)}.` + - `${encodeURIComponent(data.widget)}.js?t=` + - Math.floor(Date.now() / 36e5); + validateData( + data, + [['publisher', 'website'], ['container', 'website'], 'widget'], + ['url', 'options'] + ); global.uniqId = ( '00000' + Math.round(Math.random() * 100000).toString(16) @@ -42,5 +25,40 @@ export function idealmedia(global, data) { }); }); - 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.idealmedia.io/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.idealmedia.io/${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/idealmedia.md b/ads/vendors/idealmedia.md index ea1a4ec1c2ce..3bcdbccf5923 100644 --- a/ads/vendors/idealmedia.md +++ b/ads/vendors/idealmedia.md @@ -4,6 +4,19 @@ ### Basic +Latest version: +```html + + +``` + +Legacy version: ```html + +``` + +Legacy version: ```html iBillboard 300x250 banner

Idealmedia

+ data-website="473218" + data-widget="1629484">

I-Mobile 320x50 banner

@@ -1529,9 +1528,8 @@

Meg

Mgid

+ data-website="579198" + data-widget="996801">

MicroAd 320x50 banner

diff --git a/examples/amp-ad/ads.amp.html b/examples/amp-ad/ads.amp.html index 1ded4e80128c..4471866b688f 100644 --- a/examples/amp-ad/ads.amp.html +++ b/examples/amp-ad/ads.amp.html @@ -1188,8 +1188,7 @@

iBillboard 300x250 banner

Idealmedia

- +

I-Mobile 320x50 banner

@@ -1358,8 +1357,7 @@

Meg

Mgid

- +

MicroAd 320x50 banner