mihatel
mihatel

Reputation: 846

Google analytics client id cookie not set

First of all, this is first time I'm trying to setup Google Analytics and Tag Manager and need client id from _ga cookie.

I thought that including snippet gtm.js is enough but _ga is not set after that

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js? 
id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->

So my question do I need to include also snippet for analitycs.js or gtm.js is enough but I'm doing something wrong ?

Upvotes: 0

Views: 2332

Answers (2)

Marek Čech
Marek Čech

Reputation: 119

To summarize you need to follow these steps to start tracking to Google Analytics via GTM (meaning to se _ga cookie created):

  1. implement GTM to page

  2. create in the GTM management interface pageview GA Tag with desired tracking ID UA-XXXX

  3. assign trigger to this Tag - probably All Pages which is automatically created

  4. preview the tag - to see if its working and you are getting real-time hits on your page in Google Analytics interface

  5. publish the changes to the GTM container

After these steps everything should work fine and the cookie should be created.

In case of need refer to this video: https://www.youtube.com/watch?v=28d60ejfk3s

Upvotes: 2

Juan Bravo
Juan Bravo

Reputation: 9

First create variable on GTM type 1st-party cookie

Variable - GA-COOKIE 1st-party cookie On Cookie Name = _ga

Obtain ClientID from the Cookie Create one custom javascript an put this function

function() {
    var id = {{GA-COOKIE}};
    var aux;
    aux = id.split(".");
    return aux[2]+"."+aux[3];
  }

This function return the clientID

Upvotes: -1

Related Questions