Obtaining analytics clientId directly from cookie variable


Ever since cookie variable was introduced, obtaining clientId  became pretty easy . In this method, we will use the Cookie Variable in GTM.  ( old post for extracting clientId with CutsomJs)

So, let’s start with the basics that, the  “_ga” is the name of GA cookie that stores the client id.

cookie_post1

 

now we will go ahead and create a new variable of type “1st Party Cookie”  and at variable part give the name of cookie – “_ga”. This variable will extract the value of the cookie with name “_ga” .

ga_cookie_name

 

Now, as usual, debugging / previewing  the job.

gtm_cookie_variable

Getting rid of GTM host events in Mixpanel


Anyone who have played around with Mixpanel implementation with GTM would have seen BOTs triggering events like below.

mixpanel gtm

To solve the issue, we would just need some JavaScript code. But let’s see the logic before discussing that, you will notice that the Current URL of GTM generated events will be always on domain gtm-msr.appspot.com , so the best thing to do is to block events from domain / host  appspot.com.

For this, we will enclose the GTM MIXPANEL EVENT CUSTOM HTML tag in a JavaScript if statement which will check the host of the domain and execute the code.

Above, code will check if the document location and on the mismatch with appspot.com it would execute the Mixpanel event. Thus filtering out all the GTM generated events.

Obtaining Google Analytics ClientID with Tag Manager


Anyone dealing with Measurement Protocols / CRMs will always need ClientID for tasks like sending offline transactions, managing leads/ refunds etc.. so that an exact user is matched with associated hit /record.

Searching the web I found 3 ways to fetch the client using GTM, both have same procedure but different CustomJs variable.

Continue Reading

Hide adsense ads for WordPress admin with GTM


Most of WP admins who don’t like to serve ad impressions while editing / previewing blog posts nor want to use browser plugins like AdBlock (that creates file upload and lot other issues)

In this tutorial, we will discuss of blocking Adsense ads whenever a user is logged in with Admin or Editor permissions using Google Tag Manger.Continue Reading

Extracting URL Parameter with GTM and using it as a variable


Update :- now we can get a direct PRE-DEFINED URL VARIABLE as below.  With this, we just have to create a new variable type of URL and component type Query. Query Key here will the name of parameter in the URL.

For above URL the setup extract value of << parm >> will be like below:

 

url_parm

 

 

 

 

 

 

______________________

 

 

 

URL parameter extraction  is very useful in cases when there are restrictions to code directly in the website/application. This implementation will basically need a “Custom HTML” tag and a “Custom JS” variable. So let’s start off.

First make a CUSTOM HTML tag

And make a trigger such that it fires on your target page/s.  This script will extract the URL parameters from URL.

Now create a CUSTOM JS variable:

This will return the URL PARAMETER named “url_parameter”  from CUSTOM HTML tag as VARIABLE and can be use to pass through other tags like conversion tags.