简体   繁体   中英

Google Analytics Site Speed and Custom URLs

I have a small web application and I'm tracking its usage with Google Analytics. The application uses the CakePHP framework so it is organised in controllers and actions. This is what I care about in the reports, not the URLs the users see.
So in order to filter out irrelevant stuff from URLs I call the send pageview command with an artifically built URL:

var l = window.location;
ga('send', 'pageview', {
    location: l.protocol + '//' + l.hostname + '/' + controller_name + '/' + action_name,
    page: '/' + controller_name + '/' + action_name });

This also strips the additional arguments that I don't care about.

It all works fine for most of the reports like page views, flow, events etc. but not for Site Speed.

The Site Speed report shows the URLs as seen in the browser address bar (and these are different and much simpler, users don't care about my implementation of controllers and actions) and worst of all they contain action arguments which means that multiple calls to the same action are treated as different pages in the Site Speed report.

I know I can configure filtering on the Google Analytics side to skip arguments and "merge" several URLs into one.
But is there a way to make the Site Speed report honor the page argument to the pageview command?

When you originally call ga('create', 'UA-XXXX-Y') you create a tracker object. At that time the tracker object sets the URL, title, screen size, browser version, etc.

When you then call ga('send', ...) you're sending all that data to Google Analytics.

You're making the assumption that calling ga('send', 'pageview', ...) with specific page data is also updating the internally stored data on the tracker object, but that's actually not the case. (I agree it's a bit confusing.)

The solution is to update the tracker object before calling send and then the correct page data will be used for all subsequent hits.

Here's an example:

ga('set', {
  location: l.protocol + '//' + l.hostname + '/' + controller_name + '/' + action_name,
  page: '/' + controller_name + '/' + action_name
});

Now you can just do:

ga('send', 'pageview');

And everything will work fine. If you send subsequent events or social hits, those will also use your updated location and page values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM