Search code examples
google-analyticsgoogle-apimeasurement-protocolpageviews

Google Analytics - server-side timing hit (Measurement Protocol)


I created a library to use Google Analytics (Universal Analytics) on the server-side with asp.net core. It automatically creates pageview, event and timing hits for each request and sends them to Google Analytics via the Measurement Protocol.

Problem

How to imitate the timing hits that analytics.js sends automatically?

There is no documentation on how to send timing data that shows up under Site Speed / Page Timings in Google Analytics (page load time, server response time etc.). I also coulnd't reverse engineer how analytics.js sends this data.

What I tried

I tried using the related parameters (page load time and server response time) to (1) send a timing hit and to (2) add timing parameters to the pageview hit, but Google Analytics doesn't show any timing values - even after 24 hours. My current workaround is to use the user timing parameters that show up under User Timings and use the user timing label to specify the url. However, the reporting features for user timings are rather limited compared to Page Timings reporting.


Solution

  • After setting up a test website with the default analytics.js script and setting the timing sample rate to 100% I could finally log a normal page timing hit (not user timing). It has all parameters of a pageview hit plus the actual timing parameters.

    Required Parameters

    • tid=UA-123456789-1
    • t=timing
    • dl=https://example.com/a
    • dt=Some%20Title
    • plt=1513
    • pdt=3
    • dns=30
    • rrt=4
    • srt=138
    • tcp=451
    • dit=1261
    • clt=126

    Warning: Adding user timing parameters (utc, utv, utt) or omitting some of the timing parameters may cause Google Analytics to ignore the page timing hit and not show any values under 'Site Speed' and 'Page Timing'.