Skip to content

Commit

Permalink
✨ Add ppid integration to amp-ad doubleclick. (#36083)
Browse files Browse the repository at this point in the history
* Add ppid integration to amp-ad doubleclick.

* Add unit test for ppid in json.

* Update doc

* Lint
  • Loading branch information
zombifier committed Oct 8, 2021
1 parent ca6f01c commit ddaa451
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
'spsa': this.isSinglePageStoryAd
? `${pageLayoutBox.width}x${pageLayoutBox.height}`
: null,
'ppid': (this.jsonTargeting && this.jsonTargeting['ppid']) || null,
...googleBlockParameters(this),
};
}
Expand Down Expand Up @@ -957,6 +958,9 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
exclusions[exclusion] = true;
});
}
if (rtcResponse.response['ppid']) {
this.jsonTargeting['ppid'] = rtcResponse.response['ppid'];
}
}
});
if (exclusions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,14 @@ for (const {config, name} of [
/(\?|&)ptt=13(&|$)/
);
});

it('should set ppid parameter if set in json', () => {
impl.uiHandler = {isStickyAd: () => false};
element.setAttribute('json', '{"ppid": "testId"}');
return expect(impl.getAdUrl()).to.eventually.match(
/(\?|&)ppid=testId(&|$)/
);
});
});

describe('#getPageParameters', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => {
rtcTime: 100,
},
{
response: {targeting: {'a': 'foo', 'b': {e: 'f'}}},
response: {targeting: {'a': 'foo', 'b': {e: 'f'}}, ppid: 'testId'},
callout: 'www.exampleB.com',
rtcTime: 500,
},
Expand All @@ -90,6 +90,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => {
'b': {c: 'd', e: 'f'},
'z': [{a: 'b'}, {c: 'd'}],
},
ppid: 'testId',
};
testMergeRtcResponses(
rtcResponseArray,
Expand Down Expand Up @@ -323,6 +324,34 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, (env) => {
it('should return null for empty array', () => {
expect(impl.mergeRtcResponses_()).to.be.null;
});

it('should properly merge ppid', () => {
const rtcResponseArray = [
{
response: {ppid: 'testId1'},
callout: 'www.exampleA.com',
rtcTime: 100,
},
{
response: {ppid: 'testId2'},
callout: 'www.exampleB.com',
rtcTime: 500,
},
];
const expectedParams = {
ati: '2,2',
artc: '100,500',
ard: 'www.exampleA.com,www.exampleB.com',
};
const expectedJsonTargeting = {
ppid: 'testId2',
};
testMergeRtcResponses(
rtcResponseArray,
expectedParams,
expectedJsonTargeting
);
});
});

describe('rewriteRtcKeys', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Supported via `json` attribute:
- `targeting`: Sets a custom targeting parameter for this slot. Values must of the form:
- `"<key_string>":"<value_string>"` or
- `"<key_string>":["<value1>", "<value2>", ...]`. See below for example.
- `ppid`: Sets a custom provided user ID for targeting. Do not set when
serving responses to crawlers since this value is expected to be dynamic.

Example with json attribute:

Expand Down
12 changes: 11 additions & 1 deletion extensions/amp-ad-network-doubleclick-impl/doubleclick-rtc.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ The body of the response must meet the following specification:
<tr>
<td><code>{"<strong>targeting</strong>": {"key1": "value1",
"key2": "value2"},
<strong>categoryExclusions</strong>: ['cat1', 'cat2', 'cat3']} </code>
"<strong>categoryExclusions</strong>": ["cat1", "cat2", "cat3"],
"<strong>ppid</strong>": "userId"} </code>
</td>
</tr>
<tr>
Expand All @@ -75,6 +76,9 @@ The body of the response must meet the following specification:
- "categoryExclusions"
- Optional parameter
- Value is an array of categories to use for category exclusions in DFP
- "ppid"
- Optional parameter
- Value is a string to use for targeting

The RTC responses will be merged with whatever JSON targeting is specified on the amp-ad element.

Expand Down Expand Up @@ -238,6 +242,12 @@ This resulting object will then be sent on the **scp** parameter of the ad reque
https://securepubads.g.doubleclick.net/gampad/ads?.....&scp=excl_cat%3Dabc,health,sports,food,fun…...
```

### Merging ppid

It's highly recommended the PPID is retrieved from only one provider.
Regardless, if multiple RTC responses contain ppid values, then the one
requested from the last URL in the list will be chosen.

### Merging RTC Responses from Vendors and Custom URLs

The RTC responses from vendors and custom URLs are ultimately all merged together (after the vendor responses have the vendor name appended on each targeting key as specified above).
Expand Down

0 comments on commit ddaa451

Please sign in to comment.