Skip to content

Commit e98b248

Browse files
committed
feat: enable the ability to overwrite the refer origin
1 parent 385c8f4 commit e98b248

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/amplitude-client.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,10 @@ var _sendParamsReferrerUserProperties = function _sendParamsReferrerUserProperti
789789
* @private
790790
*/
791791
AmplitudeClient.prototype._getReferrer = function _getReferrer() {
792-
return typeof document !== 'undefined' ? document.referrer : '';
792+
const urlRefer = this._getReferrerFromUrlParam(this._getUrlParams());
793+
794+
if (urlRefer) return urlRefer;
795+
else typeof document !== 'undefined' ? document.referrer : '';
793796
};
794797

795798
/**
@@ -835,6 +838,14 @@ AmplitudeClient.prototype._getDeviceIdFromUrlParam = function _getDeviceIdFromUr
835838
return utils.getQueryParam(Constants.AMP_DEVICE_ID_PARAM, urlParams);
836839
};
837840

841+
/**
842+
* Try to fetch referrer from url params.
843+
* @private
844+
*/
845+
AmplitudeClient.prototype._getReferrerFromUrlParam = function _getReferrerFromUrlParam(urlParams) {
846+
return utils.getQueryParam(Constants.AMP_REFERRER_PARAM, urlParams);
847+
};
848+
838849
/**
839850
* Parse the domain from referrer info
840851
* @private

src/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default {
5050
REVENUE_REVENUE_TYPE: '$revenueType',
5151

5252
AMP_DEVICE_ID_PARAM: 'amp_device_id', // url param
53+
AMP_REFERRER_PARAM: 'amp_referrer', // url param for overwriting the document.refer
5354

5455
REFERRER: 'referrer',
5556

0 commit comments

Comments
 (0)