mixpanel-js
mixpanel-js copied to clipboard
how to track custom campaign parameters?
Hi,
We have more parameters that we would like to track on Mixpanel besides these ones:
- utm_source
- utm_medium
- utm_campaign
- utm_content
- utm_term
I've noticed that you have a function to track those, but it doesn't allow to add anything else. My first thought was to monkey patch your library but that will probably cause us to fall behind on any updates you release, I wonder if there's a better way to pass the extra parameters into the mixpanel-js library to be tracked?
https://github.com/mixpanel/mixpanel-js/blob/48f217f82a114670aae873e7e0207cefa399667d/src/utils.js#L1378
Thank you, David.
Campaign param tracking is just a lightweight convenience that the SDK offers. The params are read off the URL and saved as superproperties. You can add anything you want by calling register()
or register_once()
.
So, if I understood correctly, it can be as simple as doing?
mixpanel.register({
'utm_custom' : $.urlParam('utm_custom')
})
Yup, you'll want to use register_once
for first-touch and register
for last-touch. You may find Mixpanel's community site useful for getting answers to usage questions like these!
Important note: unlike people.set, register needs a hash. In other words:
mixpanel.people.set('property', 'value'); is the same as mixpanel.people.set({property: 'value'});
However: mixpanel.register('property', 'value'); does not work, whereas mixpanel.register({property: 'value'}); does.
It can be checked on mixpanel.cookie.props