-
Notifications
You must be signed in to change notification settings - Fork 11
Add UTM parameters to origin_referrer #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UTM parameters to origin_referrer #374
Conversation
src/modules/tracker.js
Outdated
| const utmSource = searchParams.get('utm_source'); | ||
| const utmMedium = searchParams.get('utm_medium'); | ||
| const utmCampaign = searchParams.get('utm_campaign'); | ||
|
|
||
| // Add UTM parameters to origin_referrer if they exist | ||
| if (utmSource || utmMedium || utmCampaign) { | ||
| aggregateParams.origin_referrer += '?'; | ||
|
|
||
| if (utmSource) { | ||
| aggregateParams.origin_referrer += `utm_source=${utmSource}`; | ||
| } | ||
|
|
||
| if (utmMedium) { | ||
| if (utmSource) aggregateParams.origin_referrer += '&'; | ||
| aggregateParams.origin_referrer += `utm_medium=${utmMedium}`; | ||
| } | ||
|
|
||
| if (utmCampaign) { | ||
| if (utmSource || utmMedium) aggregateParams.origin_referrer += '&'; | ||
| aggregateParams.origin_referrer += `utm_campaign=${utmCampaign}`; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might I suggest an alternative?
const utmParamKeys = ['utm_source', 'utm_medium', 'utm_campaign'];
const utmQueryParamStrArr = [];
utmParamKeys.forEach((key) => {
const utmParamValue = searchParams.get(key);
if (utmParamValue) {
utmQueryParamStrArr.push(`${key}=${utmParamValue}`);
}
});
if (utmQueryParamStrArr.length) {
aggregateParams.origin_referrer += `?${utmQueryParamStrArr.join('&')}`
}Not to nitpick on implementation, but something like this would make it easier if we needed to add in more utm fields in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that
Mudaafi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esezen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
esezen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Ahmad Mudaafi' <ahmad.mudaafi@constructor.io>
Co-authored-by: Enes Kutay SEZEN <eneskutaysezen@gmail.com>
esezen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
jjl014
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🔥
| const utmParameters = 'utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1'; | ||
| const url = `http://localhost.test/path/name?query=term&category=cat&${utmParameters}`; | ||
|
|
||
| function validateOriginReferrer(requestParams) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooo, I dig this!
Add Support for UTM parameters
Where?
Appended to the
origin_referrerparameter intracker.jsmoduleWhat are the supported parameters
Tests
validateOriginReferrer