Mixpanel Community Icon

Implementing Additional UTM Parameters in Mixpanel Tracking

·
·

How can we implement extra UTM parameters field like campid and hcpid in client side in Mixpanel?

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    Hi Mansi g., Please stand by as I search the Mixpanel knowledge base for an AI-powered answer. I normally take about 15 seconds or so. In case AI cannot answer your question, feel free to reach out to Mixpanel support at mixpanel.com/get-support. If you have follow-up questions for this thread, please tag me again with your question: @kapa.ai <follow-up question> đź‘‹

    Feel free to ask a follow-up question once I've answered by mentioning me with @kapa.ai

  • Avatar of kapa.ai
    kapa.ai
    APP
    ·
    ·

    To implement extra UTM parameters like campid and hcpid on the client side in Mixpanel, you can leverage the JavaScript SDK's ability to automatically track UTM parameters. Here's how you can do it: 1. First, ensure that these additional parameters are included in your URL structure, just like standard UTM parameters. For example: [https://yourwebsite.com/?utm_source=source&amp;utm_medium=medium&amp;campid=123&amp;hcpid=456](https://yourwebsite.com/?utm_source=source&amp;utm_medium=medium&amp;campid=123&amp;hcpid=456)2. The Mixpanel JavaScript SDK will automatically capture these parameters if they are present in the URL. According to the Mixpanel JavaScript SDK documentation, the library automatically adds UTM parameters present on the page to events fired from that page load.3. While the documentation doesn't explicitly mention custom parameters like campid and hcpid, it does state that additional parameters beyond the standard ones are tracked:

    utm_campaign utm_medium utm_term utm_content utm_id utm_source_platform utm_campaign_id utm_creative_format utm_marketing_tactic ```LBKSLBKS4. To ensure these custom parameters are captured, you may want to initialize the Mixpanel instance with the `stop_utm_persistence: true` option to disable UTM persistence across events: LBKS ```LBKS mixpanel.init('YOUR_PROJECT_TOKEN', { stop_utm_persistence: true // disable utm persistence }); ```LBKSLBKS5. If you find that your custom parameters are not being automatically captured, you can manually add them to your events using the `track` method: LBKS ```LBKS mixpanel.track('Event Name', { 'campid': 'value_from_url', 'hcpid': 'value_from_url' }); ```LBKSLBKSRemember to extract the values of 'campid' and 'hcpid' from the URL before passing them to the `track` method.LBKSBy following these steps, you should be able to implement and track extra UTM parameters like campid and hcpid on the client side in Mixpanel.

    kapa.ai is still learning and improving, please let me know how I did by reacting below.

    ℹ️ Tip: Mention @kapa.ai in the thread for follow-ups or DM the app for 1-to-1 help.