Skip to content

Commit

Permalink
✨ add ads: baidu (#19489)
Browse files Browse the repository at this point in the history
* ✨ add ads: baidu

* fix lint errors

* delete preconnect

delete preconnect, as it has the same domain with prefetch url

* Update validator test: ads.out

The new `ads.out` is regenerated by running `gulp validator --update-tests`.

* Implelmentation of renderStart and noContentAvaliable API

Following the guidance of this documentation, [ads README.md](https://github.com/ampproject/amphtml/blob/master/ads/README.md)

* fix lint errors.

* Adjust the timing of invoking renderStart

* Add JS comment

Add JS comment to explain why there is no good way to do `noContentAvailable` call.

* Rearrage the code in alphabetical order

1. rearrage the code
2. regenerate ads.out

* Modify a missing alphabetical order problem

* Modify a missing alphabetical order problem
  • Loading branch information
PengXing authored and lannka committed Dec 7, 2018
1 parent df0fd54 commit 384cf61
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 3p/integration.js
Expand Up @@ -112,6 +112,7 @@ import {amoad} from '../ads/amoad';
import {appnexus} from '../ads/appnexus';
import {appvador} from '../ads/appvador';
import {atomx} from '../ads/atomx';
import {baidu} from '../ads/baidu';
import {bidtellect} from '../ads/bidtellect';
import {brainy} from '../ads/brainy';
import {bringhub} from '../ads/bringhub';
Expand Down Expand Up @@ -330,6 +331,7 @@ register('amoad', amoad);
register('appnexus', appnexus);
register('appvador', appvador);
register('atomx', atomx);
register('baidu', baidu);
register('beopinion', beopinion);
register('bidtellect', bidtellect);
register('bodymovinanimation', bodymovinanimation);
Expand Down
5 changes: 5 additions & 0 deletions ads/_config.js
Expand Up @@ -1073,4 +1073,9 @@ export const adConfig = {
],
},

'baidu': {
prefetch: 'https://dup.baidustatic.com/js/dm.js',
renderStartImplemented: true,
},

};
58 changes: 58 additions & 0 deletions ads/baidu.js
@@ -0,0 +1,58 @@
/**
* 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,
validateData,
} from '../3p/3p';

/**
* @param {!Window} global
* @param {!Object} data
*/
export function baidu(global, data) {
validateData(data, ['cproid']);

const id = '_' + Math.random().toString(36).slice(2);
const container = global.document.createElement('div');
container.id = id;
global.document.getElementById('c').appendChild(container);

global.slotbydup = global.slotbydup || [];
global.slotbydup.push({
id: data['cproid'],
container: id,
display: 'inlay-fix',
async: true,
});

global.addEventListener('message', () => {
global.context.renderStart();
});

loadScript(
global,
'https://dup.baidustatic.com/js/dm.js',
() => {},
() => {
// noContentAvailable should be called,
// if parent iframe receives no message.
// setTimeout can work, but it's not that reliable.
// So, only the faliure of JS loading is dealed with for now.
global.context.noContentAvailable();
}
);
}
34 changes: 34 additions & 0 deletions ads/baidu.md
@@ -0,0 +1,34 @@
<!---
Copyright 2016 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.
-->

# Baidu

## Example

```html
<amp-ad width="300" height="250"
type="baidu"
data-cproid="{cproid}">
</amp-ad>
```

## Configuration

For additional detials and support, see [baidu ad union website](http://union.baidu.com/product/prod-cpro.html).

### Required Parameters

* `data-cproid` - baidu union ad id
7 changes: 7 additions & 0 deletions examples/ads.amp.html
Expand Up @@ -102,6 +102,7 @@
<option>appnexus</option>
<option>appvador</option>
<option>atomx</option>
<option>baidu</option>
<option>beopinion</option>
<option>bidtellect</option>
<option>brainy</option>
Expand Down Expand Up @@ -663,6 +664,12 @@ <h2>Atomx</h2>
data-id="1234">
</amp-ad>

<h2>Baidu</h2>
<amp-ad width="300" height="250"
type="baidu"
data-cproid="u2697398">
</amp-ad>

<amp-ad width="300" height="1"
type="beopinion"
layout="responsive"
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-ad/amp-ad.md
Expand Up @@ -231,6 +231,7 @@ See [amp-ad rules](https://github.com/ampproject/amphtml/blob/master/extensions/
- [AppNexus](../../ads/appnexus.md)
- [AppVador](../../ads/appvador.md)
- [Atomx](../../ads/atomx.md)
- [Baidu](../../ads/baidu.md)
- [BeOpinion](../amp-beopinion/amp-beopinion.md)
- [Bidtellect](../../ads/bidtellect.md)
- [brainy](../../ads/brainy.md)
Expand Down
7 changes: 7 additions & 0 deletions validator/testdata/feature_tests/ads.html
Expand Up @@ -108,6 +108,7 @@
<option>amoad</option>
<option>appnexus</option>
<option>atomx</option>
<option>baidu</option>
<option>bidtellect</option>
<option>brainy</option>
<option>bringhub</option>
Expand Down Expand Up @@ -451,6 +452,12 @@ <h2>Atomx</h2>
data-id="1234">
</amp-ad>

<h2>Baidu</h2>
<amp-ad width="300" height="250"
type="baidu"
data-cproid="u2697398">
</amp-ad>

<h2 id="bidtellect">Bidtellect</h2>
<amp-ad width=320 height=200
type="bidtellect"
Expand Down
7 changes: 7 additions & 0 deletions validator/testdata/feature_tests/ads.out
Expand Up @@ -109,6 +109,7 @@ PASS
| <option>amoad</option>
| <option>appnexus</option>
| <option>atomx</option>
| <option>baidu</option>
| <option>bidtellect</option>
| <option>brainy</option>
| <option>bringhub</option>
Expand Down Expand Up @@ -452,6 +453,12 @@ PASS
| data-id="1234">
| </amp-ad>
|
| <h2>Baidu</h2>
| <amp-ad width="300" height="250"
| type="baidu"
| data-cproid="u2697398">
| </amp-ad>
|
| <h2 id="bidtellect">Bidtellect</h2>
| <amp-ad width=320 height=200
| type="bidtellect"
Expand Down

0 comments on commit 384cf61

Please sign in to comment.