Skip to content

Commit

Permalink
1% experiment - AdSense/GAM ad request ptt parameter (#30764)
Browse files Browse the repository at this point in the history
* 1% AdSense/GAM ad ptt parameter experiment

* prettify

* address feedback

* review feedback

* lint
  • Loading branch information
keithwrightbos committed Oct 21, 2020
1 parent 5ad23a7 commit 36daaa2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
4 changes: 3 additions & 1 deletion build-system/global-configs/canary-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
"amp-ad-no-center-css": 0,
"analytics-chunks": 1,
"render-on-idle-fix": 1,
"build-in-chunks": 1
"build-in-chunks": 1,
"adsense-ptt-exp": 0.02,
"doubleclick-ptt-exp": 0.02
}
4 changes: 3 additions & 1 deletion build-system/global-configs/prod-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@
"swg-gpay-api": 1,
"swg-gpay-native": 1,
"amp-ad-no-center-css": 0,
"analytics-chunks": 1
"analytics-chunks": 1,
"adsense-ptt-exp": 0.02,
"doubleclick-ptt-exp": 0.02
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ import {domFingerprintPlain} from '../../../src/utils/dom-fingerprint';
import {getAmpAdRenderOutsideViewport} from '../../amp-ad/0.1/concurrent-load';
import {getData} from '../../../src/event-helper';
import {getDefaultBootstrapBaseUrl} from '../../../src/3p-frame';
import {
getExperimentBranch,
randomlySelectUnsetExperiments,
} from '../../../src/experiments';
import {getMode} from '../../../src/mode';
import {insertAnalyticsElement} from '../../../src/extension-analytics';
import {randomlySelectUnsetExperiments} from '../../../src/experiments';
import {removeElement} from '../../../src/dom';
import {stringHash32} from '../../../src/string';
import {utf8Decode} from '../../../src/utils/bytes';
Expand All @@ -66,6 +69,15 @@ const ADSENSE_BASE_URL = 'https://googleads.g.doubleclick.net/pagead/ads';
/** @const {string} */
const TAG = 'amp-ad-network-adsense-impl';

/** @const {string} */
const PTT_EXP = 'adsense-ptt-exp';

/** @const @enum{string} */
const PTT_EXP_BRANCHES = {
CONTROL: '21068091',
EXPERIMENT: '21068092',
};

/**
* Shared state for AdSense ad slots. This is used primarily for ad request url
* parameters that depend on previous slots.
Expand Down Expand Up @@ -220,7 +232,13 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
* @visibleForTesting
*/
divertExperiments() {
const experimentInfoList = /** @type {!Array<!../../../src/experiments.ExperimentInfo>} */ ([]);
const experimentInfoList = /** @type {!Array<!../../../src/experiments.ExperimentInfo>} */ ([
{
experimentId: PTT_EXP,
isTrafficEligible: () => true,
branches: Object.values(PTT_EXP_BRANCHES),
},
]);
const setExps = randomlySelectUnsetExperiments(
this.win,
experimentInfoList
Expand Down Expand Up @@ -323,6 +341,10 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
'format': format,
'w': sizeToSend.width,
'h': sizeToSend.height,
'ptt':
getExperimentBranch(this.win, PTT_EXP) === PTT_EXP_BRANCHES.EXPERIMENT
? 12
: null,
'iu': slotname,
'npa':
consentState == CONSENT_POLICY_STATE.INSUFFICIENT ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,14 @@ describes.realWin(
/(\?|&)is_amp=5(&|$)/
);
});
it('does not set ptt parameter by default', () =>
expect(impl.getAdUrl()).to.not.eventually.match(/(\?|&)ptt=(&|$)/));
it('sets ptt parameter', () => {
forceExperimentBranch(impl.win, 'adsense-ptt-exp', '21068092');
return expect(impl.getAdUrl()).to.eventually.match(
/(\?|&)ptt=12(&|$)/
);
});
});

// Not using arrow function here because otherwise the way closure behaves
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ const ZINDEX_EXP_BRANCHES = {
HOLDBACK: '21065357',
};

/** @const {string} */
const PTT_EXP = 'doubleclick-ptt-exp';

/** @const @enum{string} */
const PTT_EXP_BRANCHES = {
CONTROL: '21068093',
EXPERIMENT: '21068094',
};

/**
* Required size to be sent with fluid requests.
* @const {string}
Expand Down Expand Up @@ -430,6 +439,11 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
isTrafficEligible: () => true,
branches: Object.values(ZINDEX_EXP_BRANCHES),
},
{
experimentId: PTT_EXP,
isTrafficEligible: () => true,
branches: Object.values(PTT_EXP_BRANCHES),
},
]);
const setExps = this.randomlySelectUnsetExperiments_(experimentInfoList);
Object.keys(setExps).forEach(
Expand Down Expand Up @@ -559,6 +573,9 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
const {consentString, gdprApplies} = consentTuple;

return {
'ptt': this.experimentIds.includes(PTT_EXP_BRANCHES.EXPERIMENT)
? 13
: null,
'npa':
consentTuple.consentState == CONSENT_POLICY_STATE.INSUFFICIENT ||
consentTuple.consentState == CONSENT_POLICY_STATE.UNKNOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,13 @@ describes.realWin('amp-ad-network-doubleclick-impl', realWinConfig, (env) => {
expect(url).to.not.match(/(=|%2C)2106317(3|4)(%2C|&|$)/);
});
});

it('does not set ptt parameter by default', () =>
expect(impl.getAdUrl()).to.not.eventually.match(/(\?|&)ptt=(&|$)/));
it('sets ptt parameter', () => {
impl.experimentIds = ['21068094'];
return expect(impl.getAdUrl()).to.eventually.match(/(\?|&)ptt=13(&|$)/);
});
});

describe('#getPageParameters', () => {
Expand Down

0 comments on commit 36daaa2

Please sign in to comment.