Skip to content

Commit

Permalink
Adding Kargo ad network support to amp-ad (#3918)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyrusiecki authored and cramforce committed Jul 7, 2016
1 parent b15efa4 commit acae56f
Show file tree
Hide file tree
Showing 7 changed files with 135 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 @@ -78,6 +78,7 @@ import {chargeads} from '../ads/chargeads';
import {nend} from '../ads/nend';
import {adgeneration} from '../ads/adgeneration';
import {genieessp} from '../ads/genieessp';
import {kargo} from '../ads/kargo';

/**
* Whether the embed type may be used with amp-embed tag.
Expand Down Expand Up @@ -142,6 +143,7 @@ register('chargeads', chargeads);
register('nend', nend);
register('adgeneration', adgeneration);
register('genieessp', genieessp);
register('kargo', kargo);

// For backward compat, we always allow these types without the iframe
// opting in.
Expand Down
5 changes: 5 additions & 0 deletions ads/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ export const adPreconnect = {
'https://mads.at.atwola.com',
'https://aka-cdn.adtechus.com',
],
kargo: [
'https://storage.cloud.kargo.com',
'https://pubads.g.doubleclick.net',
'https://prg.kargo.com',
],
};

/**
Expand Down
76 changes: 76 additions & 0 deletions ads/kargo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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,
checkData,
validateDataExists,
computeInMasterFrame,
} from '../3p/3p';

const dataKeys = ['site', 'slot', 'options'];
const requiredDataKeys = ['site', 'slot'];

/**
* @param {!Window} global
* @param {!Object} data
*/
export function kargo(global, data) {
/*eslint "google-camelcase/google-camelcase": 0*/

// validate incoming data
checkData(data, dataKeys);
validateDataExists(data, requiredDataKeys);

// Kargo AdTag url
const kargoScriptUrl = 'https://storage.cloud.kargo.com/ad/network/tag/v3/' + data.site + '.js';

// parse extra ad call options (optional)
let options = {};
if (data.options != null) {
try {
options = JSON.parse(data.options);
} catch (e) {}
}

// Add window source reference to ad options
options.source_window = global;

computeInMasterFrame(global, 'kargo-load', function(done) {
// load AdTag in Master window
loadScript(this, kargoScriptUrl, () => {
let success = false;
if (this.Kargo != null && this.Kargo.loaded) {
success = true;
}

done(success);
});
}, success => {
if (success) {
const w = options.source_window;

// Add reference to Kargo api to this window if it's not the Master window
if (!w.context.isMaster) {
w.Kargo = w.context.master.Kargo;
}

w.Kargo.getAd(data.slot, options);
} else {
throw new Error('Kargo AdTag failed to load');
}
});
}
40 changes: 40 additions & 0 deletions ads/kargo.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.
-->

# Kargo

## Example

```html
<amp-ad
width=320
height=50
type="kargo"
data-site="_tt9gZ3qxCc2RCg6CADfLAAFR"
data-slot="_vypM8bkVCf"
data-options='{"targetParams":{"AD_ID":"test-middle","ad_id":"test-middle"}}'>
</amp-ad>
```

## Configuration

For semantics of configuration, please [contact Kargo](http://www.kargo.com/contact/).

Supported parameters:

- data-site
- data-slot
- data-options
1 change: 1 addition & 0 deletions builtins/amp-ad.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ resources in AMP. It requires a `type` argument that select what ad network is d
- [I-Mobile](../ads/imobile.md)
- [Improve Digital](../ads/improvedigital.md)
- [Industrybrains](../ads/industrybrains.md)
- [Kargo](../ads/kargo.md)
- [MANTIS](../ads/mantis.md)
- [MediaImpact](../ads/mediaimpact.md)
- [Nend](../ads/nend.md)
Expand Down
10 changes: 10 additions & 0 deletions examples/ads.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,15 @@ <h2>Nativo</h2>
data-request-url="http://localhost:9876">
</amp-ad>

<h2>Kargo</h2>
<amp-ad
width=300
height=250
type="kargo"
data-site="_tt9gZ3qxCc2RCg6CADfLAAFR"
data-slot="_vypM8bkVCf"
data-options='{"targetParams":{"AD_ID":"test-middle","ad_id":"test-middle"}}'>
</amp-ad>

</body>
</html>
1 change: 1 addition & 0 deletions test/functional/test-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('3p integration.js', () => {
expect(registrations).to.include.key('nend');
expect(registrations).to.include.key('adgeneration');
expect(registrations).to.include.key('genieessp');
expect(registrations).to.include.key('kargo');
});

it('should validateParentOrigin without ancestorOrigins', () => {
Expand Down

0 comments on commit acae56f

Please sign in to comment.