Skip to content

Commit 9d9d9f8

Browse files
authored
Adskeeper website attribute (#40045)
1 parent 08d4ac5 commit 9d9d9f8

File tree

3 files changed

+64
-28
lines changed

3 files changed

+64
-28
lines changed

ads/vendors/adskeeper.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,60 @@ import {loadScript, validateData} from '#3p/3p';
2121
* @param {!Object} data
2222
*/
2323
export function adskeeper(global, data) {
24-
validateData(data, ['publisher', 'widget', 'container'], ['url', 'options']);
25-
26-
const scriptRoot = global.document.createElement('div');
27-
scriptRoot.id = data.container;
28-
29-
global.document.body.appendChild(scriptRoot);
30-
31-
/**
32-
* Returns path for provided js filename
33-
* @param {string} publisher js filename
34-
* @return {string} Path to provided filename.
35-
*/
36-
function getResourceFilePath(publisher) {
37-
const publisherStr = publisher.replace(/[^a-zA-Z0-9]/g, '');
38-
return `${publisherStr[0]}/${publisherStr[1]}`;
39-
}
40-
41-
const url =
42-
`https://jsc.adskeeper.com/${getResourceFilePath(data.publisher)}/` +
43-
`${encodeURIComponent(data.publisher)}.` +
44-
`${encodeURIComponent(data.widget)}.js`;
24+
validateData(
25+
data,
26+
[['publisher', 'website'], ['container', 'website'], 'widget'],
27+
['url', 'options']
28+
);
4529

4630
global.uniqId = (
4731
'00000' + Math.round(Math.random() * 100000).toString(16)
4832
).slice(-5);
49-
global['ampOptions' + data.widget + '_' + global.uniqId] = data.options;
33+
window['ampOptions' + data.widget + '_' + global.uniqId] = data.options;
5034

5135
global.context.observeIntersection(function (changes) {
5236
/** @type {!Array} */ (changes).forEach(function (c) {
53-
global['intersectionRect' + data.widget + '_' + global.uniqId] =
37+
window['intersectionRect' + data.widget + '_' + global.uniqId] =
5438
c.intersectionRect;
55-
global['boundingClientRect' + data.widget + '_' + global.uniqId] =
39+
window['boundingClientRect' + data.widget + '_' + global.uniqId] =
5640
c.boundingClientRect;
5741
});
5842
});
5943

60-
loadScript(global, data.url || url);
44+
if (data.website) {
45+
const widgetContainer = document.createElement('div');
46+
widgetContainer.dataset.type = '_mgwidget';
47+
widgetContainer.dataset.widgetId = data.widget;
48+
document.body.appendChild(widgetContainer);
49+
50+
const url =
51+
`https://jsc.adskeeper.com/site/` +
52+
`${encodeURIComponent(data.website)}.js?t=` +
53+
Math.floor(Date.now() / 36e5);
54+
55+
loadScript(global, data.url || url);
56+
} else {
57+
const scriptRoot = document.createElement('div');
58+
scriptRoot.id = data.container;
59+
60+
document.body.appendChild(scriptRoot);
61+
62+
/**
63+
* Returns path for provided js filename
64+
* @param {string} publisher js filename
65+
* @return {string} Path to provided filename.
66+
*/
67+
function getResourceFilePath(publisher) {
68+
const publisherStr = publisher.replace(/[^a-zA-Z0-9]/g, '');
69+
return `${publisherStr[0]}/${publisherStr[1]}`;
70+
}
71+
72+
const url =
73+
`https://jsc.adskeeper.com/${getResourceFilePath(data.publisher)}/` +
74+
`${encodeURIComponent(data.publisher)}.` +
75+
`${encodeURIComponent(data.widget)}.js?t=` +
76+
Math.floor(Date.now() / 36e5);
77+
78+
loadScript(global, data.url || url);
79+
}
6180
}

ads/vendors/adskeeper.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ limitations under the License.
2020

2121
### Basic
2222

23+
Latest version:
24+
```html
25+
<amp-embed
26+
width="100"
27+
height="283"
28+
type="adskeeper"
29+
data-website="98765"
30+
data-widget="12345"
31+
>
32+
</amp-embed>
33+
```
34+
35+
Legacy version:
2336
```html
2437
<amp-embed
2538
width="100"
@@ -38,8 +51,13 @@ For details on the configuration semantics, please contact the ad network or ref
3851

3952
### Required parameters
4053

41-
- `data-publisher`
54+
Latest version:
4255
- `data-widget`
56+
- `data-website`
57+
58+
Legacy version:
59+
- `data-widget`
60+
- `data-publisher`
4361
- `data-container`
4462

4563
### Optional parameters

examples/amp-ad/ads.amp.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,7 @@ <h2>AdServSolutions</h2>
679679
</amp-ad>
680680

681681
<h2>AdsKeeper</h2>
682-
<amp-embed width="600" height="320" type="adskeeper" data-publisher="example.adskeeper.com" data-widget="1126814"
683-
data-container="M707443ScriptRootC1126814">
682+
<amp-embed width="600" height="320" type="adskeeper" data-website="107894" data-widget="1629491">
684683
</amp-embed>
685684

686685
<h2>AdsLoom</h2>

0 commit comments

Comments
 (0)