EzDevInfo.com

analytics.js

The hassle-free way to integrate analytics into any web application. Analytics.js - Segment

what are the values in _ga cookie?

I am using universal analytics. universal analytics creates first party cookie _ga

 _ga=1.2.286403989.1366364567;

286403989 is clientId

1366364567 is timestamp

what is 1 and 2 in _ga cookie?


Source: (StackOverflow)

How to set up page speed logging for google analytics in analytics.js

Google released the new Analytics.js (https://developers.google.com/analytics/devguides/collection/analyticsjs/). I would like to use it, and I already have everyting set up just fine, apart from site speed.

In the "old" ga.js you could do this with

_gaq.push(['_setSiteSpeedSampleRate', 50]);

This would set it so 50% of the visitors would report sitespeed to analytics.

However, for the new analytics.js I cannot get it to work. I tried the following 2:

ga('send','setSiteSpeedSampleRate',50);
ga('setSiteSpeedSampleRate',50);

But no results. Any ideas?


Source: (StackOverflow)

Advertisements

Correct syntaxis for event tracking in Google Analytics 2015

im new at implementing event tracking in analytics, this is a contact form and i would like to know if my syntaxis is correct, google analytics help is not very none code savvy friendly i think. I'm using the jQuery example they provide.

<button type="submit" class="btn btn-xl-contacto">Escríbenos</button>
<script>
$('#btn btn-xl-contacto').on('click', function() {
ga('send', 'event', 'button', 'click', 'boton-contacto');
});
</script>

Source: (StackOverflow)

In ga('create' 'ua-' 'auto'), what does 'auto' stand for?

As per the doc , 'auto' in ga('create' 'ua-' 'auto') is described as below.

opt_configObject – An optional object containing configuration field/value pairs.

But, I am not sure, I completely get this.

What is the difference between ga('create' 'ua-' 'auto') and say I give ga('create' 'ua-' 'mysite.com') ?


Source: (StackOverflow)

How to track multiple accounts using NEW analytics.js?

I need to track pageview for two accounts on one page, using Google's new analytics.js. There is plenty of tutorials and examples how to do it with older ga.js. But all I have found was this Analytics documentation page. I have written my code to suit the given example, but it only tracks views for first (default) tracker, but not for the second one.

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-XXXXXXXX-3', 'domain.com');
  ga('create', 'UA-ZZZZZZZZ-1', {'name':'b'});
  ga('send', 'pageview');
  ga('b.send', 'pageview');
</script>

Anyone has any idea what is wrong with my code ? Looks good to me according to Google's example.


Source: (StackOverflow)

Why googles analytics.js won't work in mobile webviews?

We recently wanted to switch from the old ga.js to the new analytics.js library. Everything worked great. No issues in any mobile or desktop browsers but we also have native Apps on Android and iPhone and sometimes want to display ads in a Webview. But somehow the tracking doesn't work anymore on both iPhone and Android.

When we went back using the ga.js again everything worked even the webviews. e.g. _gaq.push(['_trackEvent', 'super_ad', 'clicked'])

but the same with the new analytics.js ga('send', 'event', 'super_ad', 'clicked') won't work just for in app web views.

Is everyone having the same issues or has google just stopped the support for webviews?


Source: (StackOverflow)

Google Universal Analytics Localhost Setup

I'm trying to test GA on localhost after following the suggestions in Can you test google analytics on a localhost address?

1). but I don't see any data being send to my Google Analytics account when browsing on my localhost server and calling the JS script. I know it's executing the JS. What am I doing wrong? Here is my JS code:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-55555555-1', {
  'cookieDomain': 'none'
});

ga('send', 'timing', 'jQuery', 'Load Some Test Library', 20, 'Google Test');

2). Also, I'm confused about GA requiring a default domain to be set under Admin --> Property --> Property Settings. If I declare 'cookieDomain':'none', does that mean the domain as part of my GA account is ignored?

Cheers,

partizan


Source: (StackOverflow)

Events not being tracked in new Google Analytics (analytics.js) setup

I have a website that I am using the new Universal Analytics (analytics.js) to track. Everything is setup and working (pageviews, referrals, etc.) using the following code snippet:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-39570713-1', 'site.com');
  ga('send', 'pageview');

</script>

That is located before the </head> tag.

I am using JQuery to fire off an event. I tested the JQuery with an alert message and it is getting called, so that isn't the problem. Here is the snippet that fires when a button is clicked:

$('#submitButton').on('click', function() {
      ga('send', 'event', 'button', 'click', 'contact form');
    });

Nothing is appearing in the Events section of Analytics. I keep clicking the button, even from different computers just to make sure it isn't excluding my IP address. Because the Analytics doc that Google provides does not provide a whole lot of explanation I'm at a loss here.


Source: (StackOverflow)

Google analytics analytics.js 2 two trackers colliding?

I am using the analytics.js script to track 3 sites - two 2nd level domains and one is a subdomain... for example: dom1.com, sub.dom1.com, dom2.com

The script and site I have trouble with is the dom1.com in this example. I have 2 properties which should aggregate the following data:

Property A : dom1.com + sub.dom1.com Property B : dom1.com + sub.dom1.com + dom2.com

I have been looking for a bug in my code but can't figure out the problem, which is:

In Property A everything is aggregated correctly and both the domain and subdomain are sending their data fine. In Property B sub.dom1.com and dom2.com do send their data but dom1.com does not.

This is the script in the header of dom1.com:

ga('create', 'PropertyA', 'auto', {'name': 'trackerA'}, {'allowLinker': true});
ga('trackerA.send', 'pageview');
ga('require', 'linker');
ga('linker:autoLink', ['sub.dom1.com', 'dom1.com']);

ga('create', 'PropertyB', 'auto', {'name': 'trackerB'}, {'allowLinker': true});
ga('trackerB.send', 'pageview');
ga('require', 'linker');
ga('linker:autoLink', ['sub.dom1.com', 'dom1.com', 'dom2.com']);

I have tried moving the second tracker above in case the script is not run, but it didn't solve anything. I figure the problem is somewhere in the way I try to use the linker 2 times, but maybe do it wrong?

Thank you for any help, hope it helps someone else too.


Source: (StackOverflow)

How to trigger submit form using jQuery

I am trying to track comments on blog posts via Google Universal Analytics. I want the label to pick up the name of the blog post so I'm using jQuery to fire the event.

So far I have the following code (which is based on code I used for other websites and work fine) - obviously I must have overlooked something as it is not working:

$(document).ready(function(){
   $('#commentform').submit(function(){
     var postname = $('h2.post-title').text();
     ga('send', 'event', 'Engagement', 'Comment', postname, 5);

   });
});

Any thoughts?

(Sorry I would link to the blog but it is not live yet)

Thanks


Source: (StackOverflow)

What is the analytics.js equivalent of _trackPageview found in ga.js

Using the previous version of google analytics (ga.js) you can track a virtual page view using the _trackPageview method to record when something is downloaded or some other metric if desired. Using the new analytics.js what is the syntax to track a virtual page view?


Source: (StackOverflow)

Jquery script to catch link click events for Universal Analytics

I am trying to set up event tracking via Google Universal analytics. I found a script example that would appear to do exactly what I need - i.e. track various anchor clicks in the page and categorize them accordingly. However my javascript understanding is still rudimentary and I need help to understand why this script would not work. Basically click events appear not to be triggered at all. I checked - the script is loaded alright and can display an alertbox just upon loading. The script is placed the last in the head part of the page, after the analytics.js and Jquery are loaded.

Hopefully this is something obvious that I am missing, many thanks. Robert

<script type='text/javascript'>
if (typeof jQuery != 'undefined') {
    var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
    var baseHref = '';
    if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
    var hrefRedirect = '';

    jQuery('body').on('click', 'a', function(event) {

        var el = jQuery(this);
        var track = true;
        var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') : '';
        var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
        if (!href.match(/^javascript:/i)) {
            var elEv = []; elEv.value=0, elEv.non_i=false;
            if (href.match(/^mailto\:/i)) {
                elEv.category = 'email';
                elEv.action = 'click';
                elEv.label = href.replace(/^mailto\:/i, '');
                elEv.loc = href;
            }
            else if (href.match(filetypes)) {
                var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
                elEv.category = 'download';
                elEv.action = 'click-' + extension[0];
                elEv.label = href.replace(/ /g,'-');
                elEv.loc = baseHref + href;
            }
            else if (href.match(/^https?\:/i) && !isThisDomain) {
                elEv.category = 'external';
                elEv.action = 'click';
                elEv.label = href.replace(/^https?\:\/\//i, '');
                elEv.non_i = true;
                elEv.loc = href;

            }
            else if (href.match(/^https?\:/i) && isThisDomain) {
                elEv.category = 'internal';
                elEv.action = 'click';
                elEv.label = href.replace(/^https?\:\/\//i, '');
                elEv.non_i = true;
                elEv.loc = href;

            }            
            else if (href.match(/^tel\:/i)) {
                elEv.category = 'telephone';
                elEv.action = 'click';
                elEv.label = href.replace(/^tel\:/i, '');
                elEv.loc = href;
            }
            else track = false;


            if (track) {
                var ret = true;

                if((elEv.category == 'external' || elEv.category == 'download') && (el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') ) {
                    hrefRedirect = elEv.loc;

                    ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
                        'nonInteraction': elEv.non_i ,
                        'hitCallback':gaHitCallbackHandler
                    });

                    ret = false;
                }
                else {
                    ga('send','event', elEv.category.toLowerCase(),elEv.action.toLowerCase(),elEv.label.toLowerCase(),elEv.value,{
                        'nonInteraction': elEv.non_i
                    });
                }

                return ret;
            }
        }
    });

    gaHitCallbackHandler = function() {
        window.location.href = hrefRedirect;
    }
}
</script>

Source: (StackOverflow)

Replay historical data (events) in Google Analytics

Super Google Analytics Api's rockstars :)

I've lost 10 days of events in Google Analytics, but I have a log of them in my DB.

Is there a way to replay events in GA with the correct timestamp? Meaning can I send all the events to GA using their analytics.js library with a previous date?

And will they be attached to Goals (I have some goals for some events)?

Something like: ga('send', 'event', 'my Category', 'my event name', {timeStamp: new Date("06/01/2015")})

Thanks in advance !!!!


Source: (StackOverflow)

google analytics.js and cross domain tracking

I'm confused by the Google documentation for analytics.js

Need to track cross domains, e.g. main-site.com blog-site.com

I set up a new property in Google Analytics and received the tracking code for main-site.com.

Step 1: Installed tracking code at page bottom in main-site.com

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-000000-X', 'main-site.com');
  ga('send', 'pageview');

</script>

Step 2: instructions for analytics.js for cross domain (installed on main-site.com) Add the following before script ending tag.

// Load the plugin.

ga('require', 'linker');

// Define which domains to autoLink.

ga(‘linker:autoLink’, [‘main-site.com’, ‘blog-site.com’]);

Step 3: add tracking code to blog-site.com

// UA-000000-X is the tracking code number for main-site.com

ga(‘create’, 'UA-000000-X', {
  ‘allowLinker’: true
});

Problem: we need to track traffic that does not original in main-site.com. For example, a link from Facebook to blog-site.com should still count under the main-site property in GA.


Source: (StackOverflow)

Google Analytics Tracking GA.js vs Analytics.js

I'm trying to use this code to track an event in Google Analytics

    _trackEvent(category, action, opt_label, opt_value, opt_noninteraction)

This seems to be meant to be use with the GA.js Analytics "package", however I'm using the Analytics.js

Like this

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

Is there a way I can do even tracking with this code only ? Or do I have to use

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

  (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google    -analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

Do I need both of these codes? Or is there some different way using only Analytics.js

Thanks in advance

**EDIT: Indeed I probably didn't explain what I want, it might not even possible. I want to work with Funnels on Events, and I want to use _trackEvent (that's what I thought it would do) to mark a user as having Entered the Funnel, if the event is send then we will have the normal funnel. So if 10 users enter the page and 1 clicks on the button, I would have 10 events on the Funnel with 1 success


Source: (StackOverflow)