Skip to content

Commit

Permalink
✨ add adskeeper network (#33951)
Browse files Browse the repository at this point in the history
* add adskeeper network

* fix adskeeper integration

* fix adskeeper integration
  • Loading branch information
adskeeperdev authored Oct 26, 2021
1 parent 4007122 commit bbc31c8
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
1 change: 1 addition & 0 deletions 3p/integration-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const AMP_EMBED_ALLOWED = {
_ping_: true,
'1wo': true,
'24smi': true,
adskeeper: true,
adsloom: true,
adstyle: true,
bringhub: true,
Expand Down
28 changes: 28 additions & 0 deletions 3p/vendors/adskeeper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// src/polyfills.js must be the first import.
import '#3p/polyfills';

import {register} from '#3p/3p';
import {draw3p, init} from '#3p/integration-lib';

import {adskeeper} from '#ads/vendors/adskeeper';

init(window);
register('adskeeper', adskeeper);

window.draw3p = draw3p;
9 changes: 9 additions & 0 deletions ads/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ const adConfig = jsonConfiguration({

'adservsolutions': {},

'adskeeper': {
renderStartImplemented: true,
preconnect: [
'https://jsc.adskeeper.com',
'https://servicer.adskeeper.com',
'https://s-img.adskeeper.com',
],
},

'adsloom': {
clientIdScope: 'AMP_ECID_ADSLOOM',
},
Expand Down
61 changes: 61 additions & 0 deletions ads/vendors/adskeeper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {loadScript, validateData} from '#3p/3p';

/**
* @param {!Window} global
* @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-z0-9]/g, '');
return `${publisherStr[0]}/${publisherStr[1]}`;
}

const url =
`https://jsc.adskeeper.com/${getResourceFilePath(data.publisher)}/` +
`${encodeURIComponent(data.publisher)}.` +
`${encodeURIComponent(data.widget)}.js`;

global.uniqId = (
'00000' + Math.round(Math.random() * 100000).toString(16)
).slice(-5);
global['ampOptions' + data.widget + '_' + global.uniqId] = data.options;

global.context.observeIntersection(function (changes) {
/** @type {!Array} */ (changes).forEach(function (c) {
global['intersectionRect' + data.widget + '_' + global.uniqId] =
c.intersectionRect;
global['boundingClientRect' + data.widget + '_' + global.uniqId] =
c.boundingClientRect;
});
});

loadScript(global, data.url || url);
}
48 changes: 48 additions & 0 deletions ads/vendors/adskeeper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!---
Copyright 2021 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# AdsKeeper

## Example

### Basic

```html
<amp-embed
width="100"
height="283"
type="adskeeper"
data-publisher="amp-demo"
data-widget="12345"
data-container="demo-container"
>
</amp-embed>
```

## Configuration

For details on the configuration semantics, please contact the ad network or refer to their documentation.

### Required parameters

- `data-publisher`
- `data-widget`
- `data-container`

### Optional parameters

- `data-url`
- `data-options`
6 changes: 6 additions & 0 deletions examples/amp-ad/ads.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<option>adsense</option>
<option>adsensor</option>
<option>adservsolutions</option>
<option>adskeeper</option>
<option>adsloom</option>
<option>adsnative</option>
<option>adspeed</option>
Expand Down Expand Up @@ -775,6 +776,11 @@ <h2>AdServSolutions</h2>
data-zid="1953913050">
</amp-ad>

<h2>AdsKeeper</h2>
<amp-embed width="600" height="320" type="adskeeper" data-publisher="example.adskeeper.com" data-widget="1126814"
data-container="M707443ScriptRootC1126814">
</amp-embed>

<h2>AdsLoom</h2>
<amp-ad width="800" height="600"
type="adsloom"
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-ad/amp-ad.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ See [amp-ad rules](validator-amp-ad.protoascii) in the AMP validator specificati

- [1wo](../../ads/vendors/1wo.md)
- [24smi](../../ads/vendors/24smi.md)
- [AdsKeeper](../../ads/vendors/adskeeper.md)
- [AdsLoom](../../ads/vendors/adsloom.md)
- [Bringhub](../../ads/vendors/bringhub.md)
- [Dable](../../ads/vendors/dable.md)
Expand Down

0 comments on commit bbc31c8

Please sign in to comment.