Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gtag multiple custom dimensions

I searched the web for the solution to send multiple custom dimensions to google analytics.

the old tag ga was easy to configure like so :

ga('create', 'UA-ID', 'auto');

    ga('set', 'dimension1', value1);
    ga('set', 'dimension2', value2);
    ga('set', 'dimension3', value3);
    ga('send', 'pageview');

this would send all of the 3 custom dimensions.

the problem occurs with the new gtag.js I tried lots of ways to configure multiple custom dimensions. the documentation shows how to configure 1 custom dimension as so :

gtag('config', 'UA-ID', {
 'custom_map': {'dimension1': 'value'}
});
gtag('event','eventname', {'valuename':value});

This works [for 1 dimension] but I can't figure out how to send multiple custom dimensions.

[tried sending the object with 2 fields of dimension , tried to duplicate the config custom map with different dimensions - it didn't work]

Any ideas ?

like image 693
Maxim Kogan Avatar asked May 27 '18 12:05

Maxim Kogan


People also ask

What is one of the major differences when you want to create a custom metric versus a custom dimension?

Custom dimensions and metrics are very similar, but there is one difference: A custom dimension either has an event scope or a user scope, and a custom metric always has an event scope.

What are the 4 types of data scope in Google Analytics?

There are four levels of scope: product, hit, session, and user: Product – value is applied to the product for which it has been set (Enhanced Ecommerce only).


1 Answers

You can still use the Legacy version of the code but you have to send it inside a JSON instead, as the example

--Option I-- 
-- Set Option -- 

gtag( 'set' , {'dimension1' : "yxz"} );                      // Set a Single Element
gtag( 'set' , {'dimension2' : "abc",'dimension3' : "123"} ); // Set multiple Elements
gtag('config', 'UA-1-1');                             // Pageview with 3 cd

--Option II--
-- Map Function--


gtag('config', 'UA-ID', {
 'custom_map': {'dimension1': 'value',
                'dimension2': 'value2',
                'dimension3': 'value3'}
});
gtag('event','eventname', {'value1':"1",'value2':"2",'value3':"3"});
like image 163
Kemen Paulos Plaza Avatar answered Oct 13 '22 08:10

Kemen Paulos Plaza