Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amp-auto-ads: Wires up a holdout experiment for AdSense to study the effect of running amp-auto-ads #9261

Merged
merged 1 commit into from May 11, 2017

Conversation

tlong2
Copy link
Contributor

@tlong2 tlong2 commented May 11, 2017

Only ads that use the fast-fetch code path are labelled with experiment IDs. This is fine as fast-fetch will soon be the norm for AdSense amp-ads.

Only affects AdSense code paths.

*/
export function mergeExperimentIds(newIds, currentIdString) {
const newIdArr = newIds.split(',').filter(newId => {
return newId && !isNaN(parseInt(newId, 10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard appears to be to wrap with Number constructor and I assume we're ok with excluding 0. In addition you can just use join so this can be:

return newIds.split(',').filter(newId => Number(newId)).join(',')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/** @const {!../../src/experiments.ExperimentInfo} */
const ADSENSE_AMP_AUTO_ADS_EXPERIMENT_INFO = {
isTrafficEligible: win => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTrafficEligible: win => win.document.getElementsByTagName('AMP-AUTO-Ads').length,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @param {!Window} win
* @return {?string}
*/
export function getAdSenseAmpAutoAdsExpBranch(win) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add doc indicating this getter has the side effect of selecting into the experiment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -149,7 +149,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
jsonParameters['targeting'] || null,
jsonParameters['categoryExclusions'] || null),
},
]);
], []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making experimentIds optional so this is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -27,6 +31,16 @@ import {viewportForDoc} from '../../../src/services';
*/
class AdNetworkConfigDef {

/*eslint-disable no-unused-vars*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this if the variable name starts with unused (e.g. unusedWin)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.

@@ -172,6 +175,10 @@ export function googleAdUrl(
if (isCanary(win)) {
queryParams.push({name: 'isc', value: '1'});
}
let eids = adElement.getAttribute('data-experiment-id');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than passing experimentIds, can't you just set them on data-experiment-id when you create the amp-ad element?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to also capture existing ads on the page. So we could append them to the data attribute in the amp-ad-network-adsense-impl.js constructor, but potentially diverting an experiment in a constructor seems kind of nasty.

Another option would be to append them to the data attribute in the getUrl function in amp-ad-network-adsense-impl.js, but seems a bit strange for that function to have side-effects like that.

*/
export function mergeExperimentIds(newIds, currentIdString) {
const newIdArr = newIds.split(',').filter(newId => {
return newId && !isNaN(parseInt(newId, 10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one?

@@ -132,10 +132,13 @@ export function isReportingEnabled(ampElement) {
* Parameters that will be put at the end of the URL, where they may be
* elided for length reasons. Intended for parameters with potentially
* long values, like URLs.
* @param {!Array<string>} experimentIds Any experiments IDs (in addition to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given you expect these to be numbers, why not just make this Array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're handled as strings everywhere else and it's also the type expected by the mergeExperimentIds function, so would rather just leave as Array

@@ -132,10 +132,14 @@ export function isReportingEnabled(ampElement) {
* Parameters that will be put at the end of the URL, where they may be
* elided for length reasons. Intended for parameters with potentially
* long values, like URLs.
* @param {!Array<string>=} opt_experimentIds Any experiments IDs (in addition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given you expect these to be numbers why not be explicit: !Array=

Copy link
Contributor Author

@tlong2 tlong2 May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're handled as strings everywhere else and it's also the type expected by the mergeExperimentIds function, so would rather just leave as Array<string>

@@ -172,6 +176,12 @@ export function googleAdUrl(
if (isCanary(win)) {
queryParams.push({name: 'isc', value: '1'});
}
let eids = adElement.getAttribute('data-experiment-id');
if (opt_experimentIds) {
opt_experimentIds.forEach(experimentId => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass array of experimentIds into mergeExperimentIds as opposed to a loop the splits/joins each time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
export function mergeExperimentIds(newIds, currentIdString) {
const newIdString = newIds.filter(newId => Number(newId)).join(',');
const separator = currentIdString && newIdString ? ',' : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more readable to me...
currentIdString = currentIdString || '';
return currentIdString + (currentIdString && newIdString ? ',' : '')+newIdString;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/** @const {!../../src/experiments.ExperimentInfo} */
const ADSENSE_AMP_AUTO_ADS_EXPERIMENT_INFO = {
isTrafficEligible:
win => !!win.document.getElementsByTagName('AMP-AUTO-ADS').length,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it matters but win.document.querySelector('AMP-AUTO-ADS') may be more performant given it returns of first instance as opposed to getting all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants