GoogleChrome / GoogleChrome/lighthouse
new_audit: Don't load gtag.js if all you use is google analtyics
- 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.


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
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