Skip to content

Commit

Permalink
Content.ad: Utilize sourceUrl for validation (#6537)
Browse files Browse the repository at this point in the history
* Content.ad: Utilize sourceUrl for validation

Updated the Content.ad logic to use the sourceUrl value for publisher domain validation.

* Expose sourceUrl to ads
  • Loading branch information
jlucero-contentad authored and lannka committed Dec 8, 2016
1 parent f6fe757 commit 6dcfd05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ads/contentad.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,20 @@ export function contentad(global, data) {
cadDiv.id = 'contentad' + global.wid;
window.document.body.appendChild(cadDiv);

/* Capture or pass URL */
const host = window.context.location.host;
const domain = data.url || window.atob(data.d);
let adUrl = window.context.location.href;
/* Identify and remove CDN path */
const myreg = new RegExp(':\/\/.*?(?=([a-z0-9\-]+\.?)?' + domain + ')', 'i');
adUrl = adUrl.replace(myreg, '://');
if (data.url || !adUrl.includes(domain)) {
adUrl = adUrl.replace(host, domain);
/* Pass Source URL */
let sourceUrl = window.context.sourceUrl;
if (data.url) {
const host = window.context.location.host;
const domain = data.url || window.atob(data.d);
sourceUrl = sourceUrl.replace(host, domain);
}

/* Build API URL */
const cadApi = 'https://api.content.ad/Scripts/widget2.aspx'
+ '?id=' + encodeURIComponent(global.id)
+ '&d=' + encodeURIComponent(global.d)
+ '&wid=' + global.wid
+ '&url=' + encodeURIComponent(adUrl)
+ '&url=' + encodeURIComponent(sourceUrl)
+ '&cb=' + Date.now();

/* Call Content.ad Widget */
Expand Down
1 change: 1 addition & 0 deletions build-system/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ window.context = {};
window.context.amp3pSentinel;
window.context.clientId;
window.context.initialIntersection;
window.context.sourceUrl;

// Service Holder
window.services;
Expand Down

0 comments on commit 6dcfd05

Please sign in to comment.