I am trying to use google universal analytics and its custom dimensions.
On one page, I want to send multiple values for one (and one only) dimension.
I tried:
ga('send', 'pageview', {'dimension1': 'grumpy cat'})
ga('send', 'pageview', {'dimension1': 'happy cat'})
When I use google API, I can get for my dimension1 all the values I just sent - so it works well.
However I think (I am not sure about it) that I should not send several times a pageview hit on the same page because it would disrupt the pageview metric.
So I tried to use a custom metric (pageview is a metric after all):
ga('send', 'metric1', {'dimension1': 'grumpy cat'})
ga('send', 'metric1', {'dimension1': 'happy cat'})
But this one doesn't work at all :(
It seems ga.('send'...
only accepts pageview
but it is weird (why specify pageview
in the arguments if it is the only value possible?)
How can I solve my problem? Is it just a syntax issue, is it not possible with custom dimension / custom metric? Can I actually use pageview
to do it? Should I use custom events instead of that?
Thank you!
* edit *
I actually found out that I may use an event with a label like:
ga('send', 'event', 'cat', 'view', 'grumpy')
ga('send', 'event', 'cat', 'view', 'happy')
(If anyone can confirm it or have comments I would be happy with that)
I had a similar problem a while back. The thing is, you cannot push multiple values to a single custom variable (dimension or metric) in both Google Analytics (GA) and Universal Analytics (UA). What happens when you push more than one value to a custom variable, dimension, or metric for a single page (or session or user, depending upon the scope of the custom variable, dimension or metric, if you're using UA) is that the last reported value is the only one that is recorded. The last value overrides the previously set value. So, you have tried to record two pageviews with 2 different values for your custom variable (or dimension).
In your case, say a person loads a search results page after having included two categories, grumpy cat
and happy cat
, and you want to record both of them in a custom variable or dimension by reporting the variable (or dimension) twice, and if you send them in the order you mentioned,
ga('send', 'pageview', {'dimension1': 'grumpy cat'});
ga('send', 'pageview', {'dimension1': 'happy cat'});
you are simply recording two different pageviews (which will skew your reports in innumerable ways, depending on the number or categories you may have). For example, if a person visits more than 5 categories, you will have duplicate pageviews, and your time on page will be drastically reduced, as according to UA (or GA) these pageviews (except for the last one) would have lasted for less than one second.
Also, any events you wanted to link to those custom variables (or dimensions), would only be linked to the last pushed pageview or custom variable (or dimension). As an example, if you had an event tracking set up to identify how many people interacted with the search results, and if you then wanted to filter by category (dimension1
in your case now), to know how many people interacted with the page when dimension1
equals grumpy cat
you would get 0, as the events would have only been recorded for the pageview with ddimension1
equal to happy cat
because that was the page which GA (or UA) thinks the user had been viewing when firing the event, and that page only had dimension1
set to happy cat
. Since those two calls are async
, you would actually never be able to know if the events were sent to the pageview you think it went to, even as I explained.
The better way to record this type of data would be to use url-encoded category names, space separated, and a space appended to the end of the list also. As an example, you must send the pageview as,
ga('send','pageview',{'dimension1':'grumpy-cat happy-cat '});
or better, as,
ga('set',{'dimension1':'grumpy-cat happy-cat '});
ga('send','pageview');
Note the space at the end also. This extra space allows you to filter any report based on the custom variable using the reg-ex <categoryName>\s
. As an example, to find out how many people viewed a page with category Grumpy Cat, you will filter your report such that the dimension1
matches regex grumpy\-cat\s
. I have escaped the -
character in regex using \-
, and \s
stands for a whitespace character. The good thing is, such a report will fetch you all pageviews (or whatever you want to look at), those with only the grumpy cat
as category name, as well as those pages which have grumpy cat
in the categories to which a page belongs.
A way to add subcategories is to send dimensions as cat1 cat1-subcat1 cat1-subcat2 cat2 cat2-subcat1
so that the regex cat1\s
will take care of all category level pages, whereas the regex cat1
will take care of all pages which have category cat1
or which have a subcategory belonging to cat1
.
Hope that helps. :)
On a side note, using events for views of a page containing a category is not a nice way of recording it. Because, if you assign dimensions (and this is one of the reasons why custom dimensions were introduced, as different sites have different categories and Google can't name all), your events will also carry the dimensions of the page and it helps a lot to identify which categories are in need of what, by simply segmenting your reports by, in your case, dimension1
. For example, you will get to know which category has highest SEO visits and which has the best conversion rates, and stuff. Happy analysing! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With