Skip to content

Instantly share code, notes, and snippets.

@jeandcr
Last active November 9, 2018 11:25
Show Gist options
  • Select an option

  • Save jeandcr/0e63fbc9a4b89907ecad51f5ace6dce3 to your computer and use it in GitHub Desktop.

Select an option

Save jeandcr/0e63fbc9a4b89907ecad51f5ace6dce3 to your computer and use it in GitHub Desktop.

Revisions

  1. jeandcr revised this gist Nov 9, 2018. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions ClientID_GTM_var.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,20 @@
    /**
    * This snippet is meant to return your
    * analytics client ID, of your web visitor
    * to a variable of your choosing.
    *
    * This REQUIRES that you have Classic/Universal Analytics.
    *
    * Step-by-step:
    * 1. Go to your GTM container. (https://tagmanager.google.com)
    * 2. Go to Variables.
    * 3. Under 'User-Defined Variables', press 'New'.
    * 4. Choose 'Custom Javascript' as Variable type.
    * 5. Copy and paste the code below.
    * 6. Voilà, preview your changes and see your Variable
    * be declared on the 'Window Loaded' event.
    *
    */
    function(){
    try {
    var tracker = ga.getAll()[0];
  2. jeandcr created this gist Nov 9, 2018.
    8 changes: 8 additions & 0 deletions ClientID_GTM_var.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    function(){
    try {
    var tracker = ga.getAll()[0];
    return tracker.get("clientId");
    } catch(e) {
    return false;
    }
    }