I am using ga for my website.
but when i call track event like this
_gaq.push(['_trackEvent', 'abc', 'def','pqr','xyz']);
it does not work but when i call function by removing last parameter i.e 'xyz' it works properly it looks like this
_gaq.push(['_trackEvent', 'abc', 'def','pqr']);
where _gaq is an array which contains my ga account no. and domain info.
my concern is I want to pass four parameter with '_trackEvent' parameter like this..
_gaq.push(['_trackEvent', category, action,label,value]);
but this is not working.
Plz help
The Google Analytics API Event Tracking Guide states that the trackEvent method accepts 5 parameters:
category (required)
action (required)
label (optional)
value (optional)
non-interactive boolean (optional)
The second-to-last parameter (value) has to be an integer, and so does not work when a string is passed.
Related
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).
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.
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.
I have a search functionality set up in my website, which uses a third party extension retrieve the search results. The search terms are not passed as query parameters.
Below is my sample URL for my search results:
mysite.com/search/results/dGVzdA/
I cannot change the URL to pass the search terms as query parameters.
So I'm trying to send Async Tracking from the google analytics javascript :
<script>
var _gaq= _gaq || [];
_gaq.push(['_setAccount','UA-XXXXXXX-X']);
//Push search query into google analytics
if ({url_segment_1} == 'search' && {url_segment_2} == 'results')
_gaq.push(['trackPageview'],['/search/?q=test']);
else
_gap.push(['trackPageview']);
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
The javascript logic seems to be executing fine, I've tested it by placing alert options. So is there anything that I'm implementing incorrectly with respect to _gaq.push().
Could someone throw light on the same
A couple of errors:
It's _trackPageview, with an initial underscore.
The argument for _trackPageview needs to be inside the array, like:
_gaq.push(['_trackPageview','/search/?q=test']);
[edit] There's also typo: _gap.push should be _gaq.push
I want to track views for stories on my site. I want to use Google analytics to do this. Off the bat Im thinking of doing this:
pageTracker._trackEvent('Story', 'View', 'Title of story');
But I also would prefer to track with the story id as well that is passed in the url. So if I want to run a report in GA I would like to have the option of getting stats by story title or by story id that is passed via url. Is that possible?
GA by default does not strip parameters from the URL when _trackPageview is triggered, so you will see unique pages show up in your reports. For example, these two will show up as separate entries:
/somePage.html?id=1
/somePage.html?id=2
edit:
Okay, you can use this to get whatever url parameter you want:
function getParam (n) {
var x=new RegExp("[\\?&]"+n.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")+"=([^&#]*)");
var r=x.exec(window.location.href);
return(r==null)?'':r[1] ;
}
// example
var story = getParam('story'));
now story has whatever value the story=xxx URL parameter value is, and you can use story as your category value in your event tracking argument