Skip to content

Commit

Permalink
feat: enable the ability to overwrite the referrer (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao900914 authored Aug 24, 2022
1 parent 385c8f4 commit 03c0a89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/amplitude-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '';
};

/**
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down

0 comments on commit 03c0a89

Please sign in to comment.