Skip to content

Commit

Permalink
Merge tag '1454726798143' from canary into release
Browse files Browse the repository at this point in the history
  • Loading branch information
camelburrito committed Feb 9, 2016
2 parents 748b19e + b4a2669 commit 1f6aa80
Show file tree
Hide file tree
Showing 86 changed files with 2,615 additions and 467 deletions.
12 changes: 7 additions & 5 deletions 3p/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@

import './polyfills';
import {a9} from '../ads/a9';
import {adform} from '../ads/adform';
import {adreactor} from '../ads/adreactor';
import {adsense} from '../ads/adsense';
import {adtech} from '../ads/adtech';
import {plista} from '../ads/plista';
import {doubleclick} from '../ads/doubleclick';
import {dotandads} from '../ads/dotandads';
import {facebook} from './facebook';
import {manageWin} from './environment';
import {nonSensitiveDataPostMessage, listenParent} from './messaging';
Expand All @@ -37,6 +39,7 @@ import {register, run} from '../src/3p';
import {parseUrl} from '../src/url';
import {assert} from '../src/asserts';
import {taboola} from '../ads/taboola';
import {smartadserver} from '../ads/smartadserver';

/**
* Whether the embed type may be used with amp-embed tag.
Expand All @@ -47,17 +50,20 @@ const AMP_EMBED_ALLOWED = {
};

register('a9', a9);
register('adform', adform);
register('adreactor', adreactor);
register('adsense', adsense);
register('adtech', adtech);
register('plista', plista);
register('doubleclick', doubleclick);
register('taboola', taboola);
register('dotandads', dotandads);
register('_ping_', function(win, data) {
win.document.getElementById('c').textContent = data.ping;
});
register('twitter', twitter);
register('facebook', facebook);
register('smartadserver', smartadserver);

/**
* Visible for testing.
Expand Down Expand Up @@ -146,11 +152,7 @@ window.draw3p = function(opt_configCallback) {
window.context.reportRenderedEntityIdentifier =
reportRenderedEntityIdentifier;
delete data._context;
// Run this only in canary and local dev for the time being.
if (location.pathname.indexOf('-canary') ||
location.pathname.indexOf('current')) {
manageWin(window);
}
manageWin(window);
draw3p(window, data, opt_configCallback);
nonSensitiveDataPostMessage('render-start');
};
Expand Down
4 changes: 2 additions & 2 deletions 3p/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function nonSensitiveDataPostMessage(type, opt_object) {
}
const object = opt_object || {};
object.type = type;
object.sentinel = 'amp-3p';
object.sentinel = 'amp-$internalRuntimeToken$';
window.parent./*OK*/postMessage(object,
window.context.location.origin);
}
Expand All @@ -41,7 +41,7 @@ export function listenParent(type, callback) {
if (event.source != window.parent ||
event.origin != window.context.location.origin ||
!event.data ||
event.data.sentinel != 'amp-3p' ||
event.data.sentinel != 'amp-$internalRuntimeToken$' ||
event.data.type != type) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions ads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Reasons include:
- Allows browsers to run the ad in a different process from the primary page (even better security and prevents JS inside the ad to block the main page UI thread).
- Prevents ads doing less than optimal things to measure user behavior and other interference with the primary page.
- The AMP runtime may at any moment decide that there are too many iframes on a page and that memory is low. In that case it would unload ads that were previously loaded and are no longer visible. It may later load new ads in the same slot if the user scrolls them back into view.
- The AMP runtime may decide to set an ad that is currently not visible to `display: none` to reduce browser layout and compositing cost.


## The iframe sandbox
Expand Down
6 changes: 6 additions & 0 deletions ads/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const adPrefetch = {
doubleclick: 'https://www.googletagservices.com/tag/js/gpt.js',
a9: 'https://c.amazon-adsystem.com/aax2/assoc.js',
adsense: 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
dotandads: 'https://amp.ad.dotandad.com/dotandadsAmp.js',
smartadserver: 'https://ec-ns.sascdn.com/diff/js/smart.js',
};

/**
Expand All @@ -35,6 +37,7 @@ export const adPrefetch = {
* @const {!Object<string, (string|!Array<string>)>}
*/
export const adPreconnect = {
adform: 'https://track.adform.net',
adreactor: 'https://adserver.adreactor.com',
adsense: 'https://googleads.g.doubleclick.net',
taboola: 'https://cdn.taboola.com',
Expand All @@ -43,6 +46,7 @@ export const adPreconnect = {
'https://securepubads.g.doubleclick.net',
'https://tpc.googlesyndication.com',
],
dotandads: 'https://bal.ad.dotandad.com',
};

/**
Expand All @@ -53,4 +57,6 @@ export const adPreconnect = {
export const clientIdScope = {
// Add a mapping like
// adNetworkType: 'cidScope' here.
adsense: 'AMP_ECID_GOOGLE',
doubleclick: 'AMP_ECID_GOOGLE',
};
53 changes: 53 additions & 0 deletions ads/adform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2015 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 {writeScript, validateSrcPrefix, validateExactlyOne} from '../src/3p';

// Valid adform ad source hosts
const hosts = {
track: 'https://track.adform.net/',
adx: 'https://adx.adform.net/'
};

/**
* @param {!Window} global
* @param {!Object} data
*/
export function adform(global, data) {

validateExactlyOne(data, ['src', 'bn', 'mid']);
global.Adform = {ampData: data};
const src = data.src;
const bn = data.bn;
const mid = data.mid;
let url;

// Custom ad url using "data-src" attribute
if (src) {
validateSrcPrefix(Object.keys(hosts).map(type => hosts[type]), src);
url = src;
}
// Ad tag using "data-bn" attribute
else if (bn) {
url = hosts.track + 'adfscript/?bn=' + encodeURIComponent(bn) + ';msrc=1';
}
// Ad placement using "data-mid" attribute
else if (mid) {
url = hosts.adx + 'adx/?mid=' + encodeURIComponent(mid);
}

writeScript(global, url);
}
63 changes: 63 additions & 0 deletions ads/adform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!---
Copyright 2015 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.
-->

# Adform

Please refer to [Adform Help Center](http://help.adform.com) for more
information on how to get required ad tag or placement IDs.

## Examples

### Simple ad tag with `data-bn`

```html
<amp-ad width=320 height=50
type="adform"
data-bn="12345">
</amp-ad>
```

### Ad placement with `data-mid`

```html
<amp-ad width=320 height=50
type="adform"
data-mid="12345">
</amp-ad>
```

### Ad tag or placement with `src`

```html
<amp-ad width=320 height=50
type="adform"
src="https://track.adform.net/adfscript/?bn=4849385;msrc=1">
</amp-ad>
```

### Supported parameters

- `data-bn`
- `data-mid`
- `src`

Only one of the mentioned parameters should be used at the same time.

The `src` parameter must use **https** protocol and must be from one of the
allowed hosts:

- `https://track.adform.net/...`
- `https://adx.adform.net/...`
7 changes: 7 additions & 0 deletions ads/adsense.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import {checkData} from '../src/3p';
*/
export function adsense(global, data) {
checkData(data, ['adClient', 'adSlot']);
if (global.context.clientId) {
// Read by GPT for GA/GPT integration.
global.gaGlobal = {
vid: global.context.clientId,
hid: global.context.pageViewId,
};
}
/*eslint "google-camelcase/google-camelcase": 0*/
global.google_page_url = global.context.canonicalUrl;
const s = document.createElement('script');
Expand Down
26 changes: 26 additions & 0 deletions ads/dotandads.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2015 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 {writeScript} from '../src/3p';

/**
* @param {!Window} global
* @param {!Object} data
*/
export function dotandads(global, data) {
global.data = data;
writeScript(global, 'https://amp.ad.dotandad.com/dotandadsAmp.js');
}
51 changes: 51 additions & 0 deletions ads/dotandads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!---
Copyright 2015 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.
-->

# DotAndAds

## Example

300x250 box:
```html
<amp-ad width=300 height=250
type="dotandads"
data-sp="300x250-u"
data-mpo="ampTest"
data-mpt="amp-amp-all-all">
</amp-ad>
```

980x250 masthead:
```html
<amp-ad width=980 height=250
type="dotandads"
data-sp='sn-u'
data-cid="11"
data-mpo="ampTest"
data-mpt="amp-amp-all-all">
</amp-ad>
```

## Configuration

For semantics of configuration, please see ad network documentation.

Supported parameters:

- sp: sizepos (the ad size and position code)
- mpo: multipoint (an extraction parameter based on site)
- mpt: mediapoint tag (the box where the ad will be shown)
- cid: customer id
7 changes: 7 additions & 0 deletions ads/doubleclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export function doubleclick(global, data) {
'tagForChildDirectedTreatment', 'cookieOptions',
'overrideWidth', 'overrideHeight',
]);
if (global.context.clientId) {
// Read by GPT for GA/GPT integration.
global.gaGlobal = {
vid: global.context.clientId,
hid: global.context.pageViewId,
};
}
loadScript(global, 'https://www.googletagservices.com/tag/js/gpt.js', () => {
global.googletag.cmd.push(function() {
const googletag = global.googletag;
Expand Down
44 changes: 44 additions & 0 deletions ads/smartadserver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2015 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} from '../src/3p';

/**
* @param {!Window} global
* @param {!Object} data
*/
export function smartadserver(global, data) {
loadScript(global, 'https://ec-ns.sascdn.com/diff/js/smart.js', () => {
if (!global.document.getElementById(data.tag)) {
const divElt = global.document.createElement('div');
divElt.Id = data.tag;
const cElt = global.document.getElementById('c');
cElt.appendChild(divElt);
}
global.sas.cmd.push(function() {
global.sas.setup({'domain': data.domain, 'async': true});
});
global.sas.cmd.push(function() {
global.sas.call(data.call, {
'siteId': data.site,
'pageId': data.page,
'formatId': data.format,
'target': data.target,
'tagId': data.tag
});
});
});
}
Loading

0 comments on commit 1f6aa80

Please sign in to comment.