PageSpeed Insights 99/100 because of Google Analytics - How can I cache GA?

前端 未结 20 1764
無奈伤痛
無奈伤痛 2020-11-29 15:10

I\'m on a quest to reach 100/100 on PageSpeed and i\'m almost there. I\'m trying to find a good solution to cache Google Analytics.

Here is the message I get:

20条回答
  •  盖世英雄少女心
    2020-11-29 15:28

    Depending on your use of Google Analytics data, if you want basic information (such as visits, UI interactions) you might be able to not include analytics.js at all, yet still collect data in GA.

    One option may be to instead use the measurement protocol in a cached script. Google Analytics: Measurement Protocol Overview

    When you set the transport method explicitly to image, you can see how GA constructs its own image beacons.

    ga('set', 'transport', 'image');
    
    https://www.google-analytics.com/r/collect
      ?v={protocol-version}
      &tid={tracking-id}
      &cid={client-id}
      &t={hit-type}
      &dl={location}
    

    You could create your own GET or POST requests with the required payload.

    However, if you require a greater level of detail it probably won't be worth your effort.

提交回复
热议问题