Skip to content

Instantly share code, notes, and snippets.

@sansmischevia
Last active March 21, 2018 22:12
Show Gist options
  • Select an option

  • Save sansmischevia/f40b958eac52cb792e4a2e7c4478f424 to your computer and use it in GitHub Desktop.

Select an option

Save sansmischevia/f40b958eac52cb792e4a2e7c4478f424 to your computer and use it in GitHub Desktop.

Revisions

  1. sansmischevia revised this gist Mar 21, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions mixpanel-last-touch-UTM.js
    Original file line number Diff line number Diff line change
    @@ -37,6 +37,4 @@ function campaignParams() {
    mixpanel.register(params);
    }



    campaignParams();
  2. sansmischevia created this gist Mar 21, 2018.
    42 changes: 42 additions & 0 deletions mixpanel-last-touch-UTM.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    function getQueryParam(url, param) {
    // Expects a raw URL
    param = param.replace(/[[]/, "\[").replace(/[]]/, "\]");
    var regexS = "[\?&]" + param + "=([^&#]*)",
    regex = new RegExp(regexS),
    results = regex.exec(url);
    if (results === null || (results && typeof(results[1]) !== 'string' && results[1].length)) {
    return '';
    } else {
    return decodeURIComponent(results[1]).replace(/\W/gi, ' ');
    }
    };


    function campaignParams() {
    var campaign_keywords = 'utm_source utm_medium utm_campaign utm_content utm_term'.split(' '),
    kw = '',
    params = {},
    first_params = {};

    var index;
    for (index = 0; index < campaign_keywords.length; ++index) {
    kw = getQueryParam(document.URL, campaign_keywords[index]);
    if (kw.length) {
    params[campaign_keywords[index] + ' [last touch]'] = kw;
    }
    }
    for (index = 0; index < campaign_keywords.length; ++index) {
    kw = getQueryParam(document.URL, campaign_keywords[index]);
    if (kw.length) {
    first_params[campaign_keywords[index] + ' [first touch]'] = kw;
    }
    }

    mixpanel.people.set(params);
    mixpanel.people.set_once(first_params);
    mixpanel.register(params);
    }



    campaignParams();