Yan
Yan Just a simple man.

如何添加google analytics

这里记录如何添加google analytics到网站

1. 申请google analytics账号

登录google analytics网站,并注册账号

2. 生成数据流接口

  1. 点击设置,找到Account Settings, 选择Data Streams.

Account Setting

  1. 选择Add Stream,

Stream

  1. 输入网站的地址和名称

Generate

3. 添加到网站

在生成的Stream下面,有一个添加到网站的代码

code

将其添加到网站的head中即可。以jekyll为例,

  1. _includes目录下新增google-analytics.html
1
2
3
4
5
6
7
8
9
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D6LYD0GPXC"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-D6LYD0GPXC');
</script>
  1. include到_include/head.html
1
2
3
{% include google-analytics.html %}