Skip to content

Commit

Permalink
Fix DoubleClick Fast Fetch bugs around categoryExclusions and tagForC…
Browse files Browse the repository at this point in the history
…hildDirectedTreatment (ampproject#7843)

* Fix incorrect parameter name for `tagForChildDirectedTreatment` in DoubleClick.

* Added unit test for tagForChildDirectedTreatment.

* Fixed the categoryExclusions bug in Fast Fetch DoubleClick.

* Removed parens in arrow functions to satisfy linter
  • Loading branch information
taymonbeal authored and kmh287 committed Mar 13, 2017
1 parent cd70e09 commit 04194c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
}
const rawJson = this.element.getAttribute('json');
const jsonParameters = rawJson ? JSON.parse(rawJson) : {};
const tfcd = jsonParameters['tfcd'];
const tfcd = jsonParameters['tagForChildDirectedTreatment'];
const adTestOn = isInManualExperiment(this.element);

const multiSizeDataStr = this.element.getAttribute('data-multi-size');
Expand Down Expand Up @@ -209,15 +209,13 @@ AMP.registerElement(
* @return {?string}
*/
function serializeTargeting(targeting, categoryExclusions) {
if (!targeting) {
return null;
}
const serialized = Object.keys(targeting).map(
key => serializeItem(key, targeting[key]));
const serialized = targeting ?
Object.keys(targeting).map(key => serializeItem(key, targeting[key])) :
[];
if (categoryExclusions) {
serialized.push(serializeItem('excl_cat', categoryExclusions));
}
return serialized.join('&');
return serialized.length ? serialized.join('&') : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,21 @@ describes.sandboxed('amp-ad-network-doubleclick-impl', {}, () => {
'&dtd=[0-9]+$'));
});
});

it('handles tagForChildDirectedTreatment', () => {
element.setAttribute('json', '{"tagForChildDirectedTreatment": 1}');
new AmpAd(element).upgradeCallback();
return impl.getAdUrl().then(url => {
expect(url).to.match(/&tfcd=1&/);
});
});

it('handles categoryExclusions without targeting', () => {
element.setAttribute('json', '{"categoryExclusions": "sports"}');
new AmpAd(element).upgradeCallback();
return impl.getAdUrl().then(url => {
expect(url).to.match(/&scp=excl_cat%3Dsports&/);
});
});
});
});

0 comments on commit 04194c9

Please sign in to comment.