Skip to content

Instantly share code, notes, and snippets.

@agarbund
Last active September 4, 2018 10:54
Show Gist options
  • Select an option

  • Save agarbund/5436ddfacd9f4d0b5ba4e90c362fb5a3 to your computer and use it in GitHub Desktop.

Select an option

Save agarbund/5436ddfacd9f4d0b5ba4e90c362fb5a3 to your computer and use it in GitHub Desktop.

Revisions

  1. agarbund revised this gist Sep 4, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion utm_params_adder.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ $(document).ready(function() {
    $('a').each(function() {
    var link = this.href, prefix, params = '';
    if(
    link.match(/yulife\.com[/$]/) &&
    link.match(domainRegexp) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
  2. agarbund revised this gist Sep 4, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion utm_params_adder.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // script which reads UTM params from the URL and adds them to all links on the current page
    $(document).ready(function() {
    var utms = ['medium', 'source', 'campaign', 'term', 'content'], utmStrings = [];
    var domain = 'yulife.com';
    var domain = ''; // add domain here, only links to given domain will be siffixed with utm params
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));
    utms.forEach(function(utm) {
    var match = window.location.search.match(new RegExp('utm_' + utm + '=([^&]+)'));
  3. agarbund revised this gist Sep 4, 2018. 1 changed file with 19 additions and 12 deletions.
    31 changes: 19 additions & 12 deletions utm_params_adder.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,24 @@
    // script which reads UTM params from the URL and adds them to all links on the current page
    $(document).ready(function() {
    var utmMedium = ''; // put utm_medium value here
    var utmSource = ''; // put utm_source value here
    var domain = ''; // put domain here (utm params will be added only to links from that domain)
    var utms = ['medium', 'source', 'campaign', 'term', 'content'], utmStrings = [];
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    utms.forEach(function(utm) {
    var match = window.location.search.match(new RegExp('utm_' + utm + '=([^&]+)'));
    if(match) {
    utmStrings.push('utm_' + utm + '=' + match[1]);
    }
    });
    if(utmStrings.length) {
    $('a').each(function() {
    var link = this.href, prefix, params = '';
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + utmStrings.join('&');
    }
    });
    }
    });
  4. agarbund revised this gist Sep 4, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions utm_params_adder.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    $(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var utmMedium = ''; // put utm_medium value here
    var utmSource = ''; // put utm_source value here
    var domain = ''; // put domain here (utm params will be added only to links from that domain)
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
  5. agarbund revised this gist Sep 4, 2018. 2 changed files with 0 additions and 60 deletions.
    60 changes: 0 additions & 60 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -1,60 +0,0 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    </head>
    <body>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <a href="https://www.yulife.com/some/link">Some link</a>
    <a href="https://www.yulife.com/another-link/">Another link</a>
    <a href="https://www.yulife.com">Main page</a>
    <a href="https://www.yulife.com/">Slash</a>
    <a href="https://yulife.com/">No wwww</a>
    <a href="https://yulife.com/">No wwww</a>
    <a href="https://yulife.com/?utm_medium=abc">With UTM</a>
    <a href="https://yulife.com/?haha=hoho&utm_medium=abc">With UTM 2</a>
    <a href="https://yulife.com/?haha=hoho">Params no UTM</a>
    <a href="https://yahoo.com/">Not yulife</a>
    <a href="https://yulife.commercial.com/">Not yulife</a>
    <script id="jsbin-javascript">
    $(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    }
    });
    });
    </script>



    <script id="jsbin-source-javascript" type="text/javascript">$(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    }
    });
    });</script></body>
    </html>
    File renamed without changes.
  6. agarbund created this gist Sep 4, 2018.
    60 changes: 60 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    </head>
    <body>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <a href="https://www.yulife.com/some/link">Some link</a>
    <a href="https://www.yulife.com/another-link/">Another link</a>
    <a href="https://www.yulife.com">Main page</a>
    <a href="https://www.yulife.com/">Slash</a>
    <a href="https://yulife.com/">No wwww</a>
    <a href="https://yulife.com/">No wwww</a>
    <a href="https://yulife.com/?utm_medium=abc">With UTM</a>
    <a href="https://yulife.com/?haha=hoho&utm_medium=abc">With UTM 2</a>
    <a href="https://yulife.com/?haha=hoho">Params no UTM</a>
    <a href="https://yahoo.com/">Not yulife</a>
    <a href="https://yulife.commercial.com/">Not yulife</a>
    <script id="jsbin-javascript">
    $(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    }
    });
    });
    </script>



    <script id="jsbin-source-javascript" type="text/javascript">$(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    }
    });
    });</script></body>
    </html>
    17 changes: 17 additions & 0 deletions jsbin.jiqiwag.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    $(document).ready(function() {
    var utmMedium = 'referral';
    var utmSource = 'ladder_landing_book_a_demo';
    var domain = 'yulife.com';
    var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));

    $('a').each(function() {
    var link = this.href, prefix;
    if(
    link.match(/yulife\.com[/$]/) &&
    !link.match(/[?&]utm_/)
    ) {
    prefix = link.match(/\?/) ? '&' : '?';
    this.href = link + prefix + 'utm_medium=' + utmMedium + '&utm_source=' + utmSource;
    }
    });
    });