From 689e1177d5099f0a0ed887c8b083cf039d421b8c Mon Sep 17 00:00:00 2001 From: Kelson Warner Date: Fri, 11 Sep 2020 12:32:53 -0700 Subject: [PATCH 1/7] GROWTH-1094 add logAttributionCapturedEvent option to log Amplitude Events when attribution data is captured --- src/amplitude-client.js | 23 ++++++++++++++++++++--- src/constants.js | 4 +++- src/options.js | 1 + test/browser/amplitudejs.html | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 78722ddd..aba906ce 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -354,14 +354,28 @@ AmplitudeClient.prototype._migrateUnsentEvents = function _migrateUnsentEvents(c * @private */ AmplitudeClient.prototype._trackParamsAndReferrer = function _trackParamsAndReferrer() { + let utmProperties; + let referrerProperties + let gclidProperties; if (this.options.includeUtm) { - this._initUtmData(); + utmProperties = this._initUtmData(); } if (this.options.includeReferrer) { - this._saveReferrer(this._getReferrer()); + referrerProperties = this._saveReferrer(this._getReferrer()); } if (this.options.includeGclid) { - this._saveGclid(this._getUrlParams()); + gclidProperties = this._saveGclid(this._getUrlParams()); + } + if (this.options.logAttributionCapturedEvent) { + const attributionProperties = Object.assign( + {}, + utmProperties, + referrerProperties, + gclidProperties + ); + if (Object.keys(attributionProperties).length > 0) { + this.logEvent(Constants.ATTRIBUTION_EVENT, attributionProperties); + } } }; @@ -675,6 +689,7 @@ AmplitudeClient.prototype._initUtmData = function _initUtmData(queryParams, cook cookieParams = cookieParams || this.cookieStorage.get('__utmz'); var utmProperties = getUtmData(cookieParams, queryParams); _sendParamsReferrerUserProperties(this, utmProperties); + return utmProperties; }; /** @@ -739,6 +754,7 @@ AmplitudeClient.prototype._saveGclid = function _saveGclid(urlParams) { } var gclidProperties = {'gclid': gclid}; _sendParamsReferrerUserProperties(this, gclidProperties); + return gclidProperties; }; /** @@ -778,6 +794,7 @@ AmplitudeClient.prototype._saveReferrer = function _saveReferrer(referrer) { 'referring_domain': this._getReferringDomain(referrer) }; _sendParamsReferrerUserProperties(this, referrerInfo); + return referrerInfo; }; /** diff --git a/src/constants.js b/src/constants.js index 45bf6984..db68297e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -37,5 +37,7 @@ export default { UTM_MEDIUM: 'utm_medium', UTM_CAMPAIGN: 'utm_campaign', UTM_TERM: 'utm_term', - UTM_CONTENT: 'utm_content' + UTM_CONTENT: 'utm_content', + + ATTRIBUTION_EVENT: 'attribution captured' }; diff --git a/src/options.js b/src/options.js index 0b16980d..8e4ae039 100644 --- a/src/options.js +++ b/src/options.js @@ -30,6 +30,7 @@ export default { includeUtm: false, language: language.getLanguage(), logLevel: 'WARN', + logAttributionCapturedEvent: false, optOut: false, onError: () => {}, platform, diff --git a/test/browser/amplitudejs.html b/test/browser/amplitudejs.html index 4c60be84..79b60de4 100644 --- a/test/browser/amplitudejs.html +++ b/test/browser/amplitudejs.html @@ -89,7 +89,7 @@ }