Skip to content

Commit

Permalink
✨ Add new attribute to mgid and idealmedia ad components (ampproject#…
Browse files Browse the repository at this point in the history
…40044)

* 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
  • Loading branch information
velichkin authored Aug 9, 2024
1 parent b7a2045 commit d384cbb
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 59 deletions.
4 changes: 3 additions & 1 deletion ads/_a4a-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
64 changes: 41 additions & 23 deletions ads/vendors/idealmedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
20 changes: 19 additions & 1 deletion ads/vendors/idealmedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

### Basic

Latest version:
```html
<amp-embed
width="100"
height="283"
type="idealmedia"
data-website="98765"
data-widget="12345"
>
</amp-embed>
```

Legacy version:
```html
<amp-embed
width="100"
Expand All @@ -22,8 +35,13 @@ For details on the configuration semantics, please contact the ad network or ref

### Required parameters

- `data-publisher`
Latest version:
- `data-widget`
- `data-website`

Legacy version:
- `data-widget`
- `data-publisher`
- `data-container`

### Optional parameters
Expand Down
64 changes: 41 additions & 23 deletions ads/vendors/mgid.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@ import {loadScript, validateData} from '#3p/3p';
* @param {!Object} data
*/
export function mgid(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 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.mgid.com/${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)
Expand All @@ -42,5 +25,40 @@ export function mgid(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.mgid.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.mgid.com/${getResourceFilePath(data.publisher)}/` +
`${encodeURIComponent(data.publisher)}.` +
`${encodeURIComponent(data.widget)}.js?t=` +
Math.floor(Date.now() / 36e5);

loadScript(global, data.url || url);
}
}
20 changes: 19 additions & 1 deletion ads/vendors/mgid.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

### Basic

Latest version:
```html
<amp-embed
width="100"
height="283"
type="mgid"
data-website="98765"
data-widget="12345"
>
</amp-embed>
```

Legacy version:
```html
<amp-embed
width="100"
Expand All @@ -22,8 +35,13 @@ For details on the configuration semantics, please contact the ad network or ref

### Required parameters

- `data-publisher`
Latest version:
- `data-widget`
- `data-website`

Legacy version:
- `data-widget`
- `data-publisher`
- `data-container`

### Optional parameters
Expand Down
10 changes: 4 additions & 6 deletions examples/amp-ad/ads.amp.esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,8 @@ <h2>iBillboard 300x250 banner</h2>
<h2>Idealmedia</h2>
<amp-ad width="600" height="320"
type="idealmedia"
data-publisher="test_20190314_vt-24403_appr1.com"
data-widget="689384"
data-container="M416878ScriptRootC689384">
data-website="473218"
data-widget="1629484">
</amp-ad>

<h2>I-Mobile 320x50 banner</h2>
Expand Down Expand Up @@ -1529,9 +1528,8 @@ <h2>Meg</h2>
<h2>Mgid</h2>
<amp-ad width="600" height="320"
type="mgid"
data-publisher="barada.com"
data-widget="353317"
data-container="M207275ScriptRootC353317">
data-website="579198"
data-widget="996801">
</amp-ad>

<h2>MicroAd 320x50 banner</h2>
Expand Down
6 changes: 2 additions & 4 deletions examples/amp-ad/ads.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,7 @@ <h2>iBillboard 300x250 banner</h2>
</amp-ad>

<h2>Idealmedia</h2>
<amp-ad width="600" height="320" type="idealmedia" data-publisher="testsok150917-d1.com" data-widget="167018"
data-container="M278974ScriptRootC167018">
<amp-ad width="600" height="320" type="idealmedia" data-website="473218" data-widget="1629484">
</amp-ad>

<h2>I-Mobile 320x50 banner</h2>
Expand Down Expand Up @@ -1358,8 +1357,7 @@ <h2>Meg</h2>
</amp-ad>

<h2>Mgid</h2>
<amp-ad width="600" height="320" type="mgid" data-publisher="barada.com" data-widget="353317"
data-container="M207275ScriptRootC353317">
<amp-ad width="600" height="320" type="mgid" data-website="579198" data-widget="996801">
</amp-ad>

<h2>MicroAd 320x50 banner</h2>
Expand Down

0 comments on commit d384cbb

Please sign in to comment.