mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

how to track custom campaign parameters?

Open Davidslv opened this issue 6 years ago • 4 comments

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.

Davidslv avatar Dec 18 '18 10:12 Davidslv

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().

tdumitrescu avatar Dec 18 '18 17:12 tdumitrescu

So, if I understood correctly, it can be as simple as doing?

mixpanel.register({
  'utm_custom' : $.urlParam('utm_custom')
})

Davidslv avatar Dec 20 '18 11:12 Davidslv

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!

tdumitrescu avatar Dec 20 '18 13:12 tdumitrescu

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

dncrht avatar Jan 08 '19 15:01 dncrht