zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Add gtag.js to your site

JS to your add Site
2023-09-11 14:14:17 时间

Add gtag.js to your site

The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform. This page describes how to use gtag.js to configure a site for Google Analytics. For general (i.e. non-product specific) gtag.js documentation, read the gtag.js developer guide.

To install the global site tag, copy the following code and paste it immediately after the <head> tag on every page of your site. Replace GA_MEASUREMENT_ID with the ID of the Google Analytics property to which you want to send data. You need only one global snippet per page.

 
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){window.dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'GA_MEASUREMENT_ID');
</script>

This snippet loads the gtag.js library, establishes GA_MEASUREMENT_ID as the default Google Analytics property ID, and sends a pageview hit to Google Analytics.

 

这个里面有github的两个repository的示例代码

https://www.cnblogs.com/chucklu/p/16495120.html