Google analytics analytics.js giving average page load time as zero - universal-analytics

I have been trying to use analytics.js to track my average page load time under Behaviour --> Site Speed --> Page Timings. I am using (as already mentioned) analytics.js i.e Universal Analytics instead of ga.js i.e Classic Analytics since that is what is recommended in the documentations. I am tracking it for my localhost application
My issue is that the average page load time is not being reflected at all, although 'pageview' is reflected properly. It shows a zero for all pages across the application.
This is the script that I included for the analytics
<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-XXXXXX-Y', {'cookieDomain': 'none', 'siteSpeedSampleRate': 100}); //cookie domain is none since I am testing in localhost -- siteSpeedSampleRate set to 100 is the code I included for tracking page load time
ga('send', 'pageview');
ga('send', { //Code to send UserTiming
'hitType': 'event',
'timingCategory': 'category',
'timingVar': 'lookup',
'timingValue': '123',
'timingLabel': 'myUserTime'
});
</script>
As mentioned in the comments, cookie domain is none since I am testing in localhost and siteSpeedSampleRate set to 100 is the code I included for tracking page load time as suggested in the documentation. I am also sending the User Timing as suggested in the documentation of analytics.js User Timings
My questions are :
What should I do to get the average page load time of each page. I searched a lot and am not being to get the proper javascript snippet.
I included the user timing javascript snippet a two days later than I included the 'pageview'. So is it like it will take some time to get reflected in the analytics dashboard? If so, how much time.
Please help me get a clearer idea. Thanks in advance.!

This answer here helped me solve my problem. I just reemoved the cookieDomain here and changed the line to this
ga('create', 'UA-XXXXXX-Y', {'siteSpeedSampleRate': 100});

Related

Google Universal Analytics - Should campaign parameters be set manually?

We use Google Universal Analytics on site example.com.
I've generated my site campaign URL : http://example.com/?utm_source=newsletter&utm_medium=email&utm_campaign=partnership
I want GA to be notified that URL was accessed with campaign parameters. How should I do it ? Is it automatically done ? I can't find mention of "utm" parameters in Universal documentation.
I think I should set each campaign parameter cf. https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference
ga('set', 'campaignName', '(direct)');
ga('set', 'campaignSource', '(direct)');
ga('set', 'campaignMedium', 'organic');
ga('set', 'campaignId', 'ID');
and then :
ga('send', 'pageview');
It seems very much "complicated" for something that should be a common task when GA/campaign are used.
Any idea ?
Thanks for your help,
Philip.
Once you have created your link with the utm parameters, tracking is done automatically. You can find the reports under Acquisition / Campaign.
After more testing : I have a source page which includes a destination iframe. Source page has GA and Universal enabled. Destination has only Universal.
Source URL contains campaign utm parameters, iframe URL is build with Universal decorate method, which gives : "http://myiframe/?_ga=xxxxx" (notice there's no utm parameters in iframe URL). Iframe actually sends campaign information, as it can be seen with Universal debug mode enabled in browser console "sent beacon" log.
Whath I understand is : it work automatically with decorate method if source URL contains utm parameters, but if it's not the case, information is lost in destination iframe, unless you manually add those campaingn parameters to iframe URL like : "http://myiframe/?_ga=xxxxx&_utmz=xxxxx". Campaign information is stored by GA in source cookie, but not transfered to destination.
Not sure, but one convenient way to add utm parameters to iframe URL (so, if there are not already in source URL), could be to use Universal decorate and GA pageTracker._getLinkerUrl to get all needed information.

Google analytics API how to set user's location

I'm using google Analytics API in extended way. My page manages alot of events what user does.
Since I exactly can tell where user is from (Locally targeted advertisment) I would like to set user's exact location, so it appears in analytics.
Is that possible?
For example it would look like:
ga('send', 'pageview', {
'page': '/pagename',
'location': 'City/district name'
});
That way, I could tell how many clients from which place are currently on my site.
Google Analytics out the box will detect the IP of the user and detect the region/country/city.
But if you want to check that with the data you capture, I would put it in an event and/or custom dimension. e.g.
ga('send', 'event', 'user', 'geolocation', '{{yourLocationVar}}');
Event tracking info here.
Custom dimensions details here, needs a bit more setup but nicer reports

Trying to figure a simple way to redirect users to a mobile website

I am trying to figure out how to redirect users who land on a desktop website to a different URL for mobile devices, specifically apple and android devices.
I have read several posts related to this here on StackOverflow, and am really battling to piece the information together to actually get it done.
Is there a reasonably straightforward way, with steps I can follow, for me to implement such a thing? Unfortunately I have experience with HTML and CSS, very little javascript, and no PHP at all.
Any advice on where i should be looking or which direction to take would be a great help, bearing in mind that I have been reading up on what i can find here.
You will need javascript (or some similar technology) to do this sort of detection. Here's a function I've used in the past that works pretty well (credit where credit is due: script taken from detectmobilebrowsers.com):
<script type="text/javascript">
window.mobilecheck = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
return check;
}
if(window.mobilecheck()) {
window.location = 'your_mobile_url';
}
</script>
If you place this script in the <HEAD></HEAD> section of your desktop site, it will redirect the users with mobile devices to your mobile site (your_mobile_url). It uses a big, scary regular expression to determine if the visitor is identified as using a mobile browser.
Ideally, you'd also have some server-side technology (Python, ASP, PHP or similar) that stores a session variable that the user has been redirected. That way, if they return to the desktop version by choice, they're not forced back into the mobile version of your site.

firefox pagemod include sometimes not working?

The piece of code for a firefox pagemod here doesn't work on every facebook page:
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: /.*facebook.*/ ,
contentScript: "window.alert('Page matches ruleset');",
contentScriptWhen: 'end'
});
I s there any misinterpretation I have about the include part?
I have also tried "*fecebook.com" and still sometimes I don't get the alert command executed
Example:
for example for both the above solutions when i manually use the address bar to go to fecebook.com it works but when I use fecebook's home button which again goes to facebook.com it doesn't work
It doesn't hurt to be as precise as you can be with the regular expression you use:
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: /^http[s]*\:\/\/.*facebook.com\/.*/,
contentScript: "window.alert('Page matches ruleset');",
contentScriptWhen: 'end'
});
The other factor I noticed when testing this on Facebook.com is that a lot of the time a change in the page url does not necessarily mean the page is being completely reloaded. The contentscript code in your example will only file when the page is initially loaded. If you want to react to changes in the url regardless of page loads, you might need to monitor the html5 history api in your content script and then react to those changes as well.

The channel file and CDN

My main javascript (and so all the static content) is included from https://static.anuary.com. The URL that user is browsing is https://dev.anuary.com/somepath/.
Where does the channel file need to be, dev.anuary.com or static.anuary.com? At the moment it is http://static.anuary.com/channel.html.
I am asking because I am still getting the error that says:
Unsafe JavaScript attempt to access frame with URL
https://www.facebook.com/dialog/oauth?access_token=[..]&api_key=[..]&app_id=[..]&client_id=[..]&display=popup&domain=dev.anuary.com&locale=en_US&origin=1&redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D6%23cb%3Df3ac7a0544%26origin%3Dhttp%253A%252F%252Fdev.anuary.com%252Ff373e908a8%26domain%3Ddev.anuary.com%26relation%3Dopener%26frame%3Df312def42c&response_type=token%2Csigned_request&scope=email%2Cuser_birthday%2Cuser_likes%2Cuser_interests%2Cpublish_stream&sdk=joey
from frame with URL
http://dev.anuary.com/658fe23c24564ac978c31d167549c4ce8b36686d65a78ad99bfb38765d46e232/.
Domains, protocols and ports must match.
In response to #dtbarne:
Well, that's the thing – I still don't know, because I've tried bowth ways and any in case it produces the same error:
Unsafe JavaScript attempt to access frame with URL
https://www.facebook.com/dialog/oauth?access_token=[..]&api_key=[..]&app_id=[..]&client_id=[..]&display=popup&domain=dev.anuary.com&locale=en_US&origin=1&redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D6%23cb%3Df1ee31b93%26origin%3Dhttp%253A%252F%252Fdev.anuary.com%252Ff9359b2f%26domain%3Ddev.anuary.com%26relation%3Dopener%26frame%3Df18e94f9c4&response_type=token%2Csigned_request&scope=email%2Cuser_birthday%2Cuser_likes%2Cuser_interests%2Cpublish_stream&sdk=joey
from frame with URL
http://dev.anuary.com/658fe23c24564ac978c31d167549c4ce8b36686d65a78ad99bfb38765d46e232/.
Domains, protocols and ports must match.
As you said yourself, this error is not fatal, and is meant is a warning to the user that something fishy might be happening.
Facebook also marked this issue as By Design in their bugs system: Bugs > Unsafe JavaScript attempt to access frame with URL....
Also, there are plenty of threads here on stack overflow about this, for example: Facebook Authentication - Unsafe JavaScript attempt to access frame with URL.
Now that we know that this "error message" is unavoidable, use the channel as you wish, as long as everything works for you.
You don't even need to use the channel, as it states in the documentation:
The channelUrl parameter is optional, but recommended. Providing a
channel file can help address three specific known issues. First,
pages that include code to communicate across frames may cause Social
Plugins to show up as blank without a channelUrl. Second, if no
channelUrl is provided and a page includes auto-playing audio or
video, the user may hear two streams of audio because the page has
been loaded a second time in the background for cross domain
communication. Third, a channel file will prevent inclusion of extra
hits in your server-side logs. If you do not specify a channelUrl, you
can remove page views containing fb_xd_bust or fb_xd_fragment
parameters from your logs to ensure proper counts.
But it also states that:
The channel file addresses some issues with cross domain communication
in certain browsers.
So it's up to you to decide.
I personally recommend to use the channel and to serve the file from your regular server and not from the static servers.
You should however set the output to have a long caching expiration date so that your server won't get a lot of requests for this file, as they mention in the JS SDK documentation page:
<?php
$cache_expire = 60*60*24*365;
header("Pragma: public");
header("Cache-Control: max-age=".$cache_expire);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$cache_expire) . ' GMT');
?>
<script src="//connect.facebook.net/en_US/all.js"></script>
(php example, but can be done with any language).
Hope this answers clarifies things for you.
Sounds like you know the answer already. It has to be on dev.anuary.com. The purpose is to allow for communication between FB and the URL the user accessed.
The channel file should be places on the server / address the user visits, as the channel file is used to fix some cross-site javascript errors. If the user is always accessing your website using HTTPS, then you should reference the channel file using HTTPS as well as any other content.
The channel file itself should stay as <script src="//connect.[..], but make sure all your static content and JS Includes all have https in them.