-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add adskeeper network * fix adskeeper integration * fix adskeeper integration
- Loading branch information
1 parent
4007122
commit bbc31c8
Showing
7 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters