alphagov / govuk_frontend_toolkit

❗️GOV.UK Frontend Toolkit is deprecated, and will only receive major bug fixes and security patches.
MIT License
403 stars 107 forks source link

Add GOVUKTracker module #387

Closed boffbowsh closed 7 years ago

boffbowsh commented 7 years ago

This has a similar API to the GA tracker module so it’s compatible with the GOVUK.Analytics module. It sends data to the server by adding an img tag for an empty gif with the payload data encoded in the querystring of the src. This data will be picked up from the CDN logs.

It adds some additional data that the main GA tracker doesn’t add, such as performance information and the GA client ID. This is because it’s assumed that GA sends similar things by default anyway.

This data will be used alongside regular exports of content metadata to provide performance analysts with more reliable content-focused analytics data.

This is for review only at the moment to check my approach is reasonable.

TODO:

boffbowsh commented 7 years ago

This is just a spike for now to capture some data. GA isn't useful enough for performance analysts to effectively measure the success of Q1, especially where content is concerned. We need to be able to match page views to actual content items, and also have the raw performance data, not sampled. Proposal https://docs.google.com/document/d/1Tw1gG_M08jAj1lXdq1vzdozxXGvbTU_SOjGXnxFAhcs/edit#

NickColley commented 7 years ago

Looks like our other trackers have specific functions, so for this I wonder if we should break this up to have a.

'real-user-measurement-tracker' etc.

boffbowsh commented 7 years ago

The other modules are plugins, whereas this is a Tracker that is compatible with the GOVUK.GoogleAnalyticsUniversalTracker api, so can be used with GOVUK.Analytics. So I'm not sure it's the same thing.

fofr commented 7 years ago

I wonder how the image loading would affect users leaving the page, eg clicking external links or download links that get tracked as events. I don't expect it to block, but it's a risk we need to check.

fofr commented 7 years ago

Presumably we are using a GIF rather than https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon because of current browser support?

boffbowsh commented 7 years ago

We could try sendBeacon and fall back to the img tag if the browser doesn't support it? But also, this is just meant to be a spike to get some representative data. It doesn't yet need to be 100% complete in this iteration.

boffbowsh commented 7 years ago

Specs added, ready for another review. Still todo, add the screen resolutions

boffbowsh commented 7 years ago

Screen measurements added

fofr commented 7 years ago

@boffbowsh Could you include a test that makes multiple calls? Do you have an example of the network calls this makes when run on a page?

boffbowsh commented 7 years ago

I think I'll have to change sendBeacon to a $.get only - nginx won't support POST to the empty_gif endpoint.

boffbowsh commented 7 years ago

This is ready to go again now. I'll get it on integration again for final testing. Here's a HAR file as an example, viewable with http://www.softwareishard.com/har/viewer/. www.dev.gov.uk.har.zip

NickColley commented 7 years ago

Related: https://github.com/addyosmani/timing.js/ (We need to test this cross browser)

boffbowsh commented 7 years ago

I'd like to get this live to start collecting some data, and test its usefulness. Can I get another review please @tomnatt / @nickcolley ?

tomnatt commented 7 years ago

FWIW my analysis of the performance implications (throttled to a 3g connection):

Now awaiting a FEDEV to tell me I'm completely wrong 😃

boffbowsh commented 7 years ago

@nickcolley can you comment/approve please?

NickColley commented 7 years ago

We're going to review this in three weeks as part of the two week blitz, for now we'll get this in so we can test the kind of data we're getting back.

In the future I think this probably should belong in Static and we should address the issues with cross browser APIs