Skip to content

Commit

Permalink
✨ Add experiment param in GA pageview request (#23289)
Browse files Browse the repository at this point in the history
* add experiment param in GA pageview request

* add safety check

* fix lint

* add to timing request
  • Loading branch information
jonathantyng-amp authored and zhouyx committed Aug 1, 2019
1 parent 55894d5 commit aa2024c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions extensions/amp-analytics/0.1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,39 @@ export class AnalyticsConfig {

return this.fetchRemoteConfig_()
.then(this.processConfigs_.bind(this))
.then(this.addExperimentParams_.bind(this))
.then(() => this.config_);
}

/**
* TODO: cleanup #22757 @jonathantyng
* Append special param to pageview request for RC and experiment builds
* for the googleanalytics component. This is to track pageview changes
* in AB experiment
*/
addExperimentParams_() {
const type = this.element_.getAttribute('type');
const rtv = getMode().rtvVersion;
const isRc = rtv ? rtv.substring(0, 2) === '03' : false;
// eslint-disable-next-line no-undef
const isExperiment = ANALYTICS_VENDOR_SPLIT;

if (
type === 'googleanalytics' &&
(isRc || isExperiment) &&
this.config_['requests']
) {
if (this.config_['requests']['pageview']) {
this.config_['requests']['pageview'][
'baseUrl'
] += `&aae=${isExperiment}`;
}
if (this.config_['requests']['timing']) {
this.config_['requests']['timing']['baseUrl'] += `&aae=${isExperiment}`;
}
}
}

/**
* Returns a promise that resolves when remote config is ready (or
* immediately if no remote config is specified.)
Expand Down

0 comments on commit aa2024c

Please sign in to comment.