GoogleChrome / GoogleChrome/lighthouse

new_audit: Don't load gtag.js if all you use is google analtyics

Open
#10,783 7 comments 2 reactions 0 assignees View on GitHub
new_audit P2
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 14h
Merged PRs (30d)
20

Description

#### Provide a basic description of the audit
As of late 2017, the copypaste tracking code GA gives you is for gtag.js, not the old [`(i,s,o,g,r,a,m)` analytics.js code](https://developers.google.com/analytics/devguides/collection/analyticsjs/). But gtag.js just loads analytics.js, making it pretty useless.

More context from @philipwalton: https://github.com/googleanalytics/autotrack/issues/202#issuecomment-333744194
And also here: https://github.com/philipwalton/analyticsjs-boilerplate/issues/19#issuecomment-333714370

There are some benefits to using gtag if you're doing other things beyond analytics, so perhaps we can give those cases a pass. But if all someone wants is GA, then they should use that.

The idea is to detect when a page uses gtag.js and then it loads analytics.js and nothing else. And then recommend they swap it for the GA tag directly.

![image](https://user-images.githubusercontent.com/39191/81973583-2afeb980-95d9-11ea-8cde-c5e1d3b41ef0.png)
![image (7)](https://user-images.githubusercontent.com/39191/81973617-36ea7b80-95d9-11ea-80e6-96d59fd981ef.png)

More

#### How would the audit appear in the report?

wording tbd but perhaps:

Failing: Reduce gtag overhead on Google Analytics tag request
Passing: Google Analytics tag included efficiently

For UI in Failing case maybe we use the CRC renderer to show the two requests chained.

#### How is this audit different from existing ones?

None cover this.

#### What % of developers/pages will this impact?

gtag.js is probably on 80% of the sites that added google analytics in the past 3 years.
this solo-GA case is probably... 40% of them.

So.. ~30% of sites that have added GA in the past 3 years. That's a few.

#### How is the new audit making a better web for end users?

Less bytes downloaded. 84k/34k gzip'd. Less JS run.

#### What is the resourcing situation?

Core team

#### Any other links or documentation that we should check out?

* https://github.com/googleanalytics/autotrack/issues/202#issuecomment-333744194
* https://support.google.com/analytics/answer/7538414
* https://developers.google.com/analytics/devguides/collection/analyticsjs/
* 🔒 https://goto.google.com/xzlwy and https://goto.google.com/geqxq

Contributor guide

Open the contributing guide

Research direction

The issue does not name implementation files, tests, or an entry point. Start by reviewing Lighthouse's existing audit structure and the linked Google Analytics references; done means detecting the solo-Analytics gtag.js case, reporting the audit with settled wording, and covering the behavior with tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
performance, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.