Skip to content

Commit

Permalink
AMP-ad supports Seznam Imedia ad network
Browse files Browse the repository at this point in the history
  • Loading branch information
koko007 committed Apr 24, 2017
1 parent b4e4b1e commit ae58bc7
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 3p/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import {genieessp} from '../ads/genieessp';
import {gmossp} from '../ads/gmossp';
import {holder} from '../ads/holder';
import {ibillboard} from '../ads/ibillboard';
import {imedia} from '../ads/imedia';
import {imobile} from '../ads/imobile';
import {improvedigital} from '../ads/improvedigital';
import {inmobi} from '../ads/inmobi';
Expand Down Expand Up @@ -254,6 +255,7 @@ register('github', github);
register('gmossp', gmossp);
register('holder', holder);
register('ibillboard', ibillboard);
register('imedia', imedia);
register('imobile', imobile);
register('improvedigital', improvedigital);
register('industrybrains', industrybrains);
Expand Down
4 changes: 4 additions & 0 deletions ads/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export const adConfig = {

ibillboard: {},

imedia: {
prefetch: 'https://i.imedia.cz/js/im3.js',
},

imobile: {
prefetch: 'https://spamp.i-mobile.co.jp/script/amp.js',
preconnect: 'https://spad.i-mobile.co.jp',
Expand Down
74 changes: 74 additions & 0 deletions ads/imedia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* 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.
*/

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

/* global im:false */

/**
* @param {!Window} global
* @param {!Object} data
*/
export function imedia(global, data) {
validateData(data, ['id','positions']);
let positions = null;
if (data.positions) {
positions = JSON.parse(data.positions);
}
const mW = context.isMaster ? global : context.master;

// create parent element
const parentElement = document.createElement('div');
parentElement.id = data.id;
global.document.getElementById('c').appendChild(parentElement);

// array of all ad elements throught all iframes
if (!mW.elements) {
mW.elements = [];
}
mW.elements.push(parentElement);

computeInMasterFrame(global, 'imedia-load', done => {
loadScript(global, 'https://i.imedia.cz/js/im3.js', () => {
let success = false;
if (im != null) {
success = true;
mW.im = im;
mW.im.conf.referer = context.location.href;
// send request to get all ads
mW.im.getAds(positions, {AMPcallback: ads => {
mW.ads = ads;
done(success);
}});
}});
},

success => {
if (success) {
mW.elements.forEach(element => {
positions.forEach((position, index) => {
// match right elemnent and zone to write advert from adserver
if (element.id == position.id) {
position.id = element; // right element "c" to position obj.
if (mW.im.writeAd) {
mW.im.writeAd(mW.ads[index], position);
}
}
});
});
}
});
};
40 changes: 40 additions & 0 deletions ads/imedia.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!---
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.
-->

# IM.cz

## Example

```html
<amp-ad width=300 height=250
type="imedia"
data-id="p1"
data-positions='[
{"id":"p1", "zoneId":"seznam.novinky.ikona2"},
{"id":"p2", "zoneId":"seznam.novinky.ikona"}
]'
</amp-ad>
```

## Configuration

For semantics of configuration, please see [ad network documentation](https://iimedia.sbeta.cz/html/im3light/).

Supported parameters:

- width
- height
- json
26 changes: 26 additions & 0 deletions examples/ads.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2>Ad networks in <span class="broken">red color</span> have broken examples, p
<a href="#gmossp" class="broken"></a> |
<a href="#holder">Holder</a> |
<a href="#ibillboard">iBILLBOARD</a> |
<a href="#imedia">Imedia</a> |
<a href="#imobile">I-Mobile</a> |
<a href="#industrybrains">Industrybrains</a> |
<a href="#inmobi">InMobi</a> |
Expand Down Expand Up @@ -689,6 +690,31 @@ <h2 id="ibillboard">iBillboard 300x250 banner</h2>
src="https://go.eu.bbelements.com/please/code?j-21414.1.5.6.0.0._blank">
</amp-ad>

<h2 id="imedia">Imedia</h2>
<amp-ad width="300" height="250"
type="imedia"
data-id="p1"
data-positions='[
{"id":"p1", "zoneId":"seznam.novinky.ikona2"},
{"id":"p2", "zoneId":"seznam.novinky.ikona"}
]'
>
<div placeholder></div>
<div fallback></div>
</amp-ad>

<amp-ad width="300" height="100"
type="imedia"
data-id="p2"
data-positions='[
{"id":"p1", "zoneId":"seznam.novinky.ikona2"},
{"id":"p2", "zoneId":"seznam.novinky.ikona"}
]'
>
<div placeholder></div>
<div fallback></div>
</amp-ad>

<h2 id="imobile">I-Mobile 320x50 banner</h2>
<amp-ad width="320" height="50"
type="imobile"
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 @@ -128,6 +128,7 @@ The `<amp-ad>` requires width and height values to be specified according to the
- [GenieeSSP](../../ads/genieessp.md)
- [GMOSSP](../../ads/gmossp.md)
- [Holder](../../ads/holder.md)
- [Imedia](../../ads/imedia.md)
- [I-Mobile](../../ads/imobile.md)
- [iBillboard](../../ads/ibillboard.md)
- [Improve Digital](../../ads/improvedigital.md)
Expand Down

0 comments on commit ae58bc7

Please sign in to comment.