How to use a GET variable as a column in Google Analytics? - google-analytics

Say my URL is in the format of www.mywebsite.com/search?keywords=library.
Aside from using Page Level 1 or Page Level 2, is there any way I could specifically get the value of a certain GET variable to be the column of my Google Analytics table?
I currently have this table (see below), but I'm using a Page Level column which I think is kind of a cheat. I'd prefer if there was a method to just pull through a specific section of the URL.
Is there a way to do this?

You can create a custom dimension in analytics. Go to your property settings -> custom definitions -> custom dimensions -> new. Give it a name (that will appear as column label in your reports). Since the keyword is part of the url hit level scope seems the best fit (meaning that your dimension is associated with a specific user interaction - you could also choose to tie it to the complete session).
If you create the custom dimension it will have a numeric index which you use in your tracking code together with the "dimension" keyword. The following example assumes you have created your first dimension (index 1) and are using php:
ga('send', 'pageview', {
'dimension1': "<?php echo filter_input(INPUT_GET, 'keywords', FILTER_SANITIZE_ENCODED); ?>"
});
(you can use another/better filter but do not put the variable directly into your page).
Now the value is send along with the pageview. Custom dimension do not show up in the standard reports, but you can use them in custom reports or set them as secondary dimensions in your standard reports.

Related

Custom dimension vs custom metric

Ok, I'm trying to track when the users get an empty list of products.
The list is defined by a filter, I want to first know if there's a lot of people getting empty results to take some action like tracking what's the filter combination they're using, anyhow...
To picture it, this is what I want to achieve:
But I'm confused between the custom dimension and custom metrics. In my head, all I need is a custom metric (Cause the amount of empty results sounds like a metric to me).
So I created an "Empty list results" custom metric with the scope of Hit. And I'm passing just an integer 1 to this custom metric.
But it doesn't show what I need. Am I missing something?
UPDATE
Including every hit to the page, even when I'm not sending the custom metric index/value pair
In this example:
/custom-metric-test-1 does not include the custom metric index/value
/custom-metric-test-2 does include the custom metric index/value
But they both show in the report. It's like my custom metric it's just an alias for hits.
You can use a metric or a dimension, it depends on the result you want to get (read), in all cases you can have the number of times a page has a certain characteristic (in your case the empty product list).
Use a custom report, i.e. with flat table, put 'page' as a dimension and your custom metric as a metric. Page and hit are the same scope so the queried pair of elements shouldn't give you strange results.

Google Tag Manager web or Apps - conditionally use Google Analytics Settings Variable

I am setting up GTM and wonder if I can use different Google Analytics Setting variable conditionally.
For example, if Page URL contains staging then use GA Settings 1 variable, if not GA Settings 2
These two GA settings differs not only in Google Analytics Property ID but in a number of fields and custom dimensions. An alternative would be to duplicate tags which is not really what I would want to do...
I just found this post whilst trying to achieve (I think) the same thing so for the benefit of searches here is my scenario and resolution.
My client's site is accessible via two domains (.com and .ie) each of which has their own GA property, but it is a single site connected to a single GTM container. I want to send data to the appropriate GA property based on the hostname.
In the GTM container I have created a lookup table variable which lists the hostname and the GA ID as appropriate, e.g.:
www.mysite.com | UA-123123-1
www.mysite.ie | UA-234234-2
In my tag, I then can select this variable as my tracking ID. Importantly, I have to set the tag to allow overriding settings, which then allows me to set the tracking ID to this non-GAS variable type. If you just use the select box to select the GA variable then it will only allow you to select GA Settings variable types.
I have not yet tested this solution to set dimensions and fields but I would imagine you can you use a similar process.
No there is no option at the moment:
As you saw GA Settings variables don't allow you to do so
GTM environments are meant for different purposes
Using a Javascript variable returning GA Settings (see below) could work in theory but you're simply not allowed to select a variable that's not a GA Settings type from your tag, so no as well.
Workaround idea (point 3) that can't be used:
function() {
if ( ) return {{GA Settings 1}};
return {{GA Settings 2}};
}
So your options are:
Separate tags
Conditional custom HTML tag so you set the fields yourself with complete flexibility for each environment
1 tag with conditional variables: you set the fields/custom dimensions for both, except that the variables used return default values (for fields) or empty values (for custom dimensions) when they are not indeed in 1 environment.

GA custom dimension data not tracking

I have created the dimension, it's currently my only one so it has index 1. It has session level scope and is active.
I have also created a custom report to see any results I might get from it. All the report does is show the Session metric against my custom dimension. Nothing extra such as filters.
In my code (which until now was unmodified) I have added the following line between the 'create' and 'send' calls:
ga('set', 'dimension1', 'test');
Nothing is appearing in the report, or anywhere else when I use this dimension as a secondary dimension.
I have tried on a second GA property of mine and it also doesn't work there.
What am I doing wrong?
Generally, it takes 1-3 hrs for the dimension data to show in GA UI. But there are ways to check if the hit you sent contains the dimension or not.
On your browser, check the ga requests ( Like in chrome -> Inspect -> Network -> filter by collect). If you have included the dimension correctly, the pageview hit sent must contain cd1 parameter (1 is the index of the dimension). If the hit contains the dimension and value, then wait for few hours and your report will show the data.
You can also use Google Analytics Debigger to check the requests sent to ga by your website page

Tracking WP Post Tags using Google Analytics and dataLayer (GTM)

I set the dataLayer variable with the post author, tags and categories data. All these were already created as custom dimensions on Analytics.
The problem is that Post Tags and Categories are arrays, Do I have to split the arrays on Google Tag Manager? (Or something like that, IDK). I did a test with Post Categories setting up pageCategory[0] as Data Layer Variable Name (Because I need only the first category) but It's not working good.
The dataLayer looks like this:
{
"pagePostType":"post",
"pagePostType2":"single-post",
"pageCategory":["ha-kidd-knitting-supplies"],
"pageAttributes":["big-time-yarn","charles-voth","classic-shades","easy-knits","km066","knitted-cowl","textured-cowl","universal-yarn"],
"pagePostAuthor":"Charles Voth"
}
What is the best way to collect all the wordpress post tags and categories as custom dimensions on Analytics?
You need to use dot notation to access the array, so your page cateogry dataLayer variable could have a value like:
pageCategory.0
For your page attributes, they could be accessed individually:
pageAttributes.1
pageAttributes.2
etc.
Of course with multiple page attributes, this wouldn't be the best way. You should instead define your dataLayer variable to have a value of just pageAttributes, and then you can loop through this variable to populate your Custom Dimensions, and then concatenate the strings.

Google Analytics - How to filter by page, group by query string value?

I have a site with a store search that posts in the following format.
www.site.com/store-locator?city=&province=&zip[postal_code]=68123
I am trying to configure GA to give me feedback on people visiting this page and a count of specific zips searched.
example report data
/store-locator?city=&province=&zip[postal_code]=68123 1000 visits
/store-locator?city=&province=&zip[postal_code]=68456 768 visits
/store-locator?city=&province=&zip[postal_code]=68789 221 visits
note: the 'city' and 'province' values may also be populated (and I will want to mod GA to give similar data on these too).
Can anyone give feedback on how to configure GA to give me data similar to this?
Thanks!
As far as I know, the only way to look at this type of segment historically is using individual segments, which doesn't work well for an arbitrary number of zip codes. However, you can collect this data more effectively as described for new traffic. This comes up often with information like categories, tags, dates, query string variables, etc.
You can create Segments for each zip. This will work for historical analysis, but is impractical beyond a few. https://support.google.com/analytics/answer/3124493?hl=en&ref_topic=3123779
You can also use Content Grouping to create groups. This will not work historically. https://support.google.com/analytics/answer/2853423
The way I've handled this is using Custom Dimensions, which replaced Custom Variables when Universal came out. This also only works for future data.
To use Custom Dimensions, you would pass the zip code to google analytics explicitly when calling the analytics javascript code.
You can pull querystrings with javascript, or echo the parameter using something like PHP as follows:
<?php
if (array_key_exists("zip",$_GET)) { $theZip = $_GET["zip"]; }
else { $theZip = "nozip"; }
?>
And, sending the custom dimension --
ga('create', 'UA-XXXXX');
ga('set', {'dimension1': '<?php echo $theZip; ?>'})
ga('send', 'pageview');
You also need to setup the custom dimension in the Analytics Profile. Docs on custom dimensions https://developers.google.com/analytics/devguides/platform/customdimsmets
/store-locator?city=&province=&zip[postal_code]=68123 1000 visits
Step 1: In GTM, create a new macro. I called mine {{province}}
Macto Type = URL
Component Type = Query
Query Key = province
This will populate the Macro with the value of province from the query string.
Step 2: In your Google Analytics property, define a custom dimension called "province". This will assign an index key to the dimension.
Step 3: In your GTM tag for Google Analytics, you will find Custom Dimensions under more settings. Add a new dimension, apply the index number from #2 and for the dimension select the macro you created from #1
Publish and you are all set.
Now when you look in Google Analytics, you can add a secondary dimension and choose your newly created custom dimension.

Resources