-
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.
Adding Kargo ad network support to amp-ad (#3918)
- Loading branch information
1 parent
b15efa4
commit acae56f
Showing
7 changed files
with
135 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
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,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'); | ||
} | ||
}); | ||
} |
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,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 |
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
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