From 03c0a890d578db1ada383cf1e6195d71275bac44 Mon Sep 17 00:00:00 2001 From: Alyssa Yu Date: Wed, 24 Aug 2022 11:59:57 -0700 Subject: [PATCH] feat: enable the ability to overwrite the referrer (#551) --- src/amplitude-client.js | 13 ++++++++++++- src/constants.js | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 325dfe61..aa60874b 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -789,7 +789,10 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti * @private */ AmplitudeClient.prototype._getReferrer = function _getReferrer() { - return typeof document !== 'undefined' ? document.referrer : ''; + const urlRefer = this._getReferrerFromUrlParam(this._getUrlParams()); + + if (urlRefer) return urlRefer; + else return typeof document !== 'undefined' ? document.referrer : ''; }; /** @@ -835,6 +838,14 @@ AmplitudeClient.prototype._getDeviceIdFromUrlParam = function _getDeviceIdFromUr return utils.getQueryParam(Constants.AMP_DEVICE_ID_PARAM, urlParams); }; +/** + * Try to fetch referrer from url params. + * @private + */ +AmplitudeClient.prototype._getReferrerFromUrlParam = function _getReferrerFromUrlParam(urlParams) { + return utils.getQueryParam(Constants.AMP_REFERRER_PARAM, urlParams); +}; + /** * Parse the domain from referrer info * @private diff --git a/src/constants.js b/src/constants.js index 5ad6fd41..59267f29 100644 --- a/src/constants.js +++ b/src/constants.js @@ -50,6 +50,7 @@ export default { REVENUE_REVENUE_TYPE: '$revenueType', AMP_DEVICE_ID_PARAM: 'amp_device_id', // url param + AMP_REFERRER_PARAM: 'amp_referrer', // url param for overwriting the document.refer REFERRER: 'referrer',