Custom reports are empty in Google Analytics receiving data from Google Tag Manager - google-analytics

I want to create a custom report with custom dimensions and custom metrics, so I've created them as admin in GA and both have index 1.
I've added them in the dataLayer in my code:
var dataLayer = {'dimension1':'Custom Dimension 1','metric1':123456}
And after setting in GTM, I've checked data is being sent right in live mode:
But custom reports are empty, but activity on site is being registered.
This is the entire code of my site. I have tried adding both Google Tag Manager and Google Adwords codes but does not work in any case:
<body>
<script>
var dataLayer = [{
'dimension1':'My Custom Dimension 1',
'metric1': 123456
}]
</script>
<!-- Google Tag Manager -->
<!-- End Google Tag Manager -->
<h1>Nuevo alojamiento</h1>
<script>
//GA CODE
ga('create', 'UA-76206495-2', 'auto');
ga('send', 'pageview');
</script>
</body>

Pushing those values with those standard reference names in to GTM will not associate them with your hits, or make them show up in your reports. In GTM you need to grab the value of your CD and CM from the dataLayer. In this case you need to create dataLayer type variables that will give you access to dimension1 and metric1, although I would advise to rename them to something else other than the standard GA reference names, ie. dimensionX and metricX because that could be confusing. Then you need to pass the index and value for that CD and CM into whichever tag (page view, event, etc.) using those new names.
Edit: note that data won't show up in your standard reports until they have been processed, which takes up to 24 hours or so.

As nyuen told me, I have to set those values in GTM, it was done bescause, if it wouldn't, data would not been sent. These are my settings
This sends the CD and CM in all pages. Custom vars are already set.
Preview mode of CTM displays this, it was fired:
And de dataLayer contains the data (I'm going to follow you advice and use another name):
So if I leave the preview mode and publish in GTM, I'm sure information is being sent, that is the GET request I placed before. Those values era in the URL as params (cd1 and cm1), so that is the reason why I'm pretty sure information is being sent to GA
Hope this extra information helps
UPDATE 1
I've changed dataLayer values to dim1 and met1 and now met1 is set to 123456789. Also, verified UA is right.
With those changes, chain sent to Google Analytics is the same (params are cd1 and cm1 with the appropiate values)

Related

Two Google Analytics Codes - both not collecting correctly

I have inherited a site which has two GA-UA codes.
These are setup like this
// first code
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', 'pageview');
//second code
ga('create', 'UA-XXXXXXXX-1', {'name':'second'});
ga('second.send', 'pageview');
I have no idea why they are setup like this and indeed do not understand the syntax of the second tracking code
The following can be observed
THE FIRST CODE
Custom events working and being successfully collected
Linked successfully to Adwords
Only has a few months of data and therefore we don't want to use this
THE SECOND CODE
Does not record custom events
Can't link to Adwords
Has years of data attached to it that we want to use
The plan is to just use the second code
For complete brevity custom events are being triggered like this
ga('send', 'event', 'Contact', 'contact-form', 'Goals');
My questions is this
"Because it has lots of historical data we wish to use code two but it is not collecting custom events. How do I get the second code to collect custom events so we can retire the first code? "
If you use two trackers on one site you need to give a name to at least one of them, else the first tracker is overwritten when the second one is initialized.
Thus the syntax for your second piece of tracking code - when the tracker is initialized it is assigned a name, in your example "second".
If you want to send data to that tracker you need to prepend the assigned tracker name to the send call, in your example:
ga('second.send', 'event', 'Contact', 'contact-form', 'Goals');
That is why the second tracker does not receive your event tracking calls, they are only being sent to the first "unnamed" tracker (actually if a tracker name is not assigned it defaults to t0).
Also do not think you can link an Adwords account to two different Google Analytics accounts, so. you'd need to unlink the first account and then link the second one.

What is the correct syntax to set a custom dimension in Google Analytics?

I'd like to send some custom dimensions back to GA with every blog post that is read on my website - author and category.
When I set up the custom dimensions in GA I got this code to use:
var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension2', dimensionValue);
However, in the GA docs it specifies a different syntax using "send" rather than "set".
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
ga('send', 'pageview', { 'dimension4': '<?=$categories?>'});
We are using universal google analytics, but this conflicting information means I'm not sure which syntax to use.
Thanks in advance
The first code block is how you set the custom dimension (CD) that can be sent with any hit: event, pageview, transaction, etc.
The second code block is how you set the CD and send it with a pageview. So it's a specific example of the first method.
Both are valid, it's just that the second example is more complete.
When sending data to CDs, don't forget to create and define them in the GA configuration as well.

Integrate optimizely into google analytics

I have been trying to integrate optimizely into google analytics and it has proved a bit difficult than I anticipated. I am doing it through gtm which makes it slightly complicated. I have created a macro
function() {
dimension = optimizely.allExperiments[experimentId].universal_analytics.slot;
experimentIds = optimizely.activeExperiments;
variationName = optimizely.variationNamesMap;
experimentDetails = variationName + "|" + experimentIds;
return experimentDetails;
}
and joined it to a custom dimension in universal analytics tag which means this will be fired on every page but the dimension always comes back as:
'Running command: ga("set", "dimension14", undefined)'
I will really some help on this as I am struggling and the optimizely team dont know what to do either.
Thanks.
While Optimizely is best installed directly onto your page, it is possible to install Optimizely using Google Tag Manager (GTM), which is discussed here, with a complete walk through. This will ensure Optimizely fires before GA (or any other tag):
https://help.optimizely.com/hc/en-us/articles/200040095-Implementing-the-Optimizely-Snippet#tag_manager
The next part is troublesome - how can you integrate Optimizely with Google Analytics? To do so, you must insert a line of code before the GA tracking call is made ( ga('send','pageview') ). To do this, you must modify the JS in the GA call to look like the code below.
Please note, unless GTM allows you to modify their GA add on, you will need to add a custom integration in GTM for GA to place the modified code.
// Optimizely Universal Analytics Integration code
window.optimizely = window.optimizely || [];
window.optimizely.push(['activateUniversalAnalytics']);
ga('send', 'pageview');
The 'activateUniversalAnalytics' call is similar to the macro you've written above, where all it does is pass your experiment ID# (or name) and the variation # (or name) to the custom Dimension you've assigned to GA in Optimizely. One benefit of using Optimizely's integration is you can change the Dimension number per experiment inside Optimizely without making any changes to your page's source code.
If you need further assistance with this, please contact support#optimizely.com (full disclosure, I am an Optimizely employee).

Custom Dimension tracked in GTM, but not showing in UA

I tried to setup Google Tag Manager. The Pageviews are tracked correctly, but in Universal Analytics I can not see Custom Dimensions.
In Google Universal Analytics:
I have defined some custom dimensions in the Universal Analytics Profile under "Admin" -> "Custom Definitions" -> "Custom Dimensions".
The following Dimensions are relevant:
(Name) (Index)
PageView Author 7
PageView Themenwelt 8
PageView Seitentyp 9
PageView Posttyp 10
PageView Modified Date 11
In Google Tag Manager:
I have added a page Universal Analytics Tag with Track Type "Page View" and the following settings for "Custom Dimensions":
(Index) (Dimension)
7 {{Tracking Variable Posttyp}}
9 {{Tracking Variable Seitentyp}}
8 {{Tracking Variable Themenwelt}}
7 {{Tracking Variable Autor}}
11 {{Tracking Variable Modified Date}}
The values for the dimensions are fetched via Macros, using the "Javascript Variable" Macro.
Example for such a macro is just:
Global Variable Name: window.analytics_tracking_params.Author
The Variable is defined in the Website content, before the tag manager code.
When I go to the debug mode of tag manager, I can see the event being triggered, with the following debug entry for "Dimension":
{
7: Tracking Variable Autor,
8: Tracking Variable Themenwelt,
9: Tracking Variable Seitentyp,
10: Tracking Variable Posttyp,
11: Tracking Variable Modified Date,
}
The Macros resolve correctly to the values set on the website.
----------> I believe that the Google Tag Manager Setup is correct.
Again, in Google Universal Analytics:
I have created a Custom Report ("Customization" -> "+New Custom Report") with the following settings:
Metric Groups: Pageviews (Users)
Dimension Drilldowns: PageView Posttyp (Custom Dimensions)
In the report table below the Chart, there is only this message "There is no data for this view.".
This happens regardless of which Custom Dimension I chose.
----------> I believe that the Settings in Google Universal Analytics are correct, but apparently something does not work as expected.
It seems the Data is not correctly sent to Universal Analytics OR Universal Analytics is not able to process the Data and display it. Is there anything I might have forgotten or misunderstood?
I encountered a similar problem with my GTM configuration. I had my macro retrieving the values for my custom dimensions set up to fill in an empty string as a default value (see checkbox for default value: "To set the default value to be an empty string, select this option and leave the text field blank.").
Unfortunately my custom dimension was overwritten at some places with the empty string, so in GA pagehits etc. were recorded but the custom dimensions have been set to blank.
I changed that with unchecking the default value box, so instead of a empty string a nil value (or in JS: undefined) will be used instead. With that setting my custom dimension haven't got overwritten again with empty strings.
Maybe that might fix your problem as well?
see if your custom dimensions can be seen as aseconday dimension in the events sections. If you can you are probably look at standard user reports. Custom reports easily populate custom dimensions.

Accessing ClientID set by Google Analytics through Google Tag Manager

I have setup a new Universal Analytics tracking and would like to store ClientID in one of the custom dimensions slots.
The tracking tags are implemented through Google Tag Manager (using the predefined UA tag) and I am having the difficulty to passing the Client ID (via custom JavaScript Macro) with the basic pageview request.
I have named my tracker so that I can access it and this code runs without any error in console, however when used with GTM, it's returning an error.
ga.getByName('trackerGTM').get('clientId'))
produces an error:
Uncaught ReferenceError: ga is not defined
Any tips?
I assume you're firing the pageview {{url}} matches RegEx .*, correct? Could be that Universal hasn't loaded yet. Have you tried {{event}} equals gtm.dom? I haven't tested this, but it's a thought.
EDIT:
This looks like a bug. I was able to run:
function(){
var client = ga.getAll()[0].get('clientId');
return client;
}
And have it spit out the client ID with no problem.
The real problem is that GTM (Google Tag Manager) creates an object that is NOT called ga (it creates an object named ga followed by a random number), that's why 'ga' is not defined. You should try something on the lines of using the tag manager to put that client id into a javascript variable so you can access it from the page)
I was reading up on setting client ids and came across this blog link about accessing client ID in GA while using Google Tag Manager. Might be helpful.
Accessing Client ID in GA using custom dimensions

Resources