Custom Dimension doesn't show up in Google Analytics - google-analytics

I have the following custom dimension parameter that I'm sending on page view:
ga('send', 'pageview', { 'environment': 'DEV' });
(DEV changes depending on the website environment)
I logged into Google Analytics => Admin => Custom Definitions/Custom Dimensions, then "New Custom Dimension" and added "environment", Scope = Hit.
I created a custom report that included Pageviews as the Metric and "environment" as the Dimension and I don't see any information for the custom dimension I added. The js has been in there for several weeks (throughout our development cycle) so I would expect to see some information.
Am I missing a step somewhere?
Bear with me if I'm calling something by the wrong name, I'm relatively new to Google Analytics.
Thanks
JH

The custom dimensions are set by number, what you have named them in the GA interface shouldn't appear in the code. So for your example you'd have
ga('send', 'pageview', {
'dimensionX': 'DEV'
});
where X is the number of the dimension you wish to set.

Related

setting up user_id for Google Analytics

I followed the directions given when setting up the User-ID option.
I then created a view named 'user_id' for showing user_id info, but I am not seeing anything. When enabling User-ID, the code said to add the following to my tracking code.
gtag('set', {'user_id': '12345UserIdHere'});
However, when I go to the 'user_id' view, nothing is shown.
My current goal is to view which user ids were browsing the system during a given period of time.
Edit:
I am using this library:
https://www.googletagmanager.com/gtag/js?id=MY-ID-STUFF
I mostly used GTM, so I am not completely familiar with the gtag.js syntax, but I don't believe it has a "set" method. According to the documentation you'd have to set the user id in the "config" call instead:
gtag('config', 'GA_MEASUREMENT_ID', {
'user_id': 'USER_ID'
});
(Things in caps are placeholders).

Google Analytics Global Site Tag Custom Parameters

According to Google's gtag.js guide, it seems like we're able to define custom parameters. However, when using the code examples, only the Event Action gets populated. The Event Label is recorded in Google Analytics as "(not set)" and the Event Category as "general".
Code Example from developers.google.com:
gtag('event', 'video_play', {
'video_title': 'My promotional video',
'duration': '01:32'
});
It's also interesting to note that I cannot figure out how to show custom parameters as the columns in Google Analytics seem to be statically set to "Event Category", "Event Action", and "Event Label". These correspond to the default keys of "event_category", "event_action", and "event_label". Using these keys sends the values correctly. The following code works:
gtag('event', 'redirect', {
'event_category': 'Announcements',
'event_label': '/announcements/index.jsp',
Has anyone gotten custom parameters to work or is this a feature that hasn't been implemented yet in gtag.js? Is there additional configuration needed that I may have missed?
If you you were thinking of GA Custom Dimensions and Custom Metrics, yes it is available in the gtag.js / Global Site Tag syntax, see
https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets
in the form of a Map of CD indexes and attribute explicit names, followed by setting values to explicit attribute names.
for example
// Maps 'dimension2' to 'age'.
gtag('config', 'GA_MEASUREMENT_ID', {
'custom_map': {'dimension2': 'age'}
});
// Sends an event that passes 'age' as a parameter.
gtag('event', 'age_dimension', {'age': 55});
See also https://developers.google.com/analytics/devguides/collection/gtagjs/migration#custom_dimensions_and_metrics
However, gtag.js is a wrapper to make analytics.js easier to implement by hiding some its complexity.
If you are used to analytics.js, keep using it, you get more control on its behavior.
Or move to GTM, it's way more flexible.

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

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)

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.

Detect if user is already logged into LinkedIn and log the results

I'd like to track how many people hit my website that might be logged into LinkedIn. Depending on the results, I might add an interactive LinkedIn section using their API.
I already have the Javascript logic to detect if they're logged in. My question is what is the best approach to log this result? Can Google Analytics do it with a custom variable or event detection?
I'd love to report on something like, "10,000 visits to my website, of which X number of visitors were logged into LinkedIn".
Any help would be appreciated!
I believe Google Analytics Custom Tracking Variables would do the trick. Something along the lines of:
_gaq.push(['_setCustomVar',
1, // variable slot
'LinkedInUser', // variable
'true', // value
1 // variable scope, 1=visitor
]);
_gaq.push(['_trackPageview']);
For custom variables (not that is this is a user-triggered event after the initial GA page load logic, a call to _trackPageview is needed to push the data back to GA), or:
_gaq.push(['_trackEvent',
'PageView',
'LinkedIn'
]);
For custom events. Just pop something similar to that into your JS routine that checks for authed LinkedIn users.

Resources