Google Analytics & Ads 学习笔记

更新 : 2020-08-29

ads setup conversion 

refer : https://www.youtube.com/watch?v=rH6YQ2MbX30

可以 import ga 的 goal, 也可以写 code tracking

这里有一个比较大的区别是. 

ga 的 goal 一个 session 只能 1 个, 不适合用于 purchase 

ads code tracking 的话是 by event or one (30 days 内)

ga 的 goal 不适合 purchase, 那么就用 trasaction 来 tracking, 但这个可能容易 duplicate, 参考下面文章.

refer: https://www.beacontechnologies.com/blog/2015/09/google-analytics-goal-conversion-and-ecommerce-transaction-counting.aspx#:~:text=Each%20Google%20Analytics%20goal%20conversion,multiple%20times%20in%20a%20session.

 解决方法是在掉数据出来看的时候要注意 transactions id 和 count 

https://www.getelevar.com/analytics/how-to-find-duplicate-transactions-in-google-analytics/

https://support.google.com/google-ads/answer/6386790?hl=en

一个 page 如果要跑 ga 和 ads 2 个 tracking code 的话,要注意 default : 参考下面

https://developers.google.com/gtagjs/devguide/routing

更新 : 2020-08-23

要精准 tracking 到 content view 是比较难的, 大部分情况我们是 tracking page view

像 e-commerce product impression 谷歌的最佳实践就挺烂的

refer : https://www.simoahava.com/analytics/true-view-impressions-google-tag-manager/

这篇有说出一些问题, 比如 max hit 500/session, 没有使用 intersection observer

分析也是网站的一部分. 以前有做但是没有系统记入起来. 最近又 mood 就来写一下呗.

资源:

https://www.youtube.com/watch?v=9r0yYrBCNZ8 (overview 看一篇就够了)

https://daan.dev/wordpress/difference-analyics-gtag-ga-js/ (gtag.js vs ga.js)

https://www.inspectlet.com/feature/session-recording (数据太少的时候不要分析用 recorder 更好)

https://developers.google.com/analytics Google analytics dev 官网

https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_purchases gtag dev 官网

https://www.npmjs.com/package/@types/google.analytics typescript

https://enhancedecommerce.appspot.com/ ecommerce setup code demo

https://analytics.google.com/analytics/academy/ control panel 官方教学

https://ga-dev-tools.appspot.com/account-explorer/ Tools

https://support.google.com/analytics/answer/3297892?hl=en GA 正则 for channel & medium 

https://developers.google.com/tag-manager/enhanced-ecommerce tag manager e-commerce

https://developers.google.com/analytics/devguides/collection/gtagjs/events gtag event

https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_product_clicks gtag e-commerce

先讲一个大纲

做网站分析的动机有 2 个

第 1 是为了优化网站体验. 

比如动线, 交互体验等等. a/b test 如果没有收集数据,你要怎么 test 呢, 对吧。很简单的道理

第 2 是为了优化广告

分析可以让我们获取到流量来源,用户信息. 这个就方便我们做再营销或者定位广告用户等等.

甚至发掘新需求.

再讲讲怎样看 control panel.

最要就是看 "什么样的人", 从 “哪里”来到网站 "干了啥"

"什么样的人" 就是说用户数据啦. 谷歌可以给我们许多用户信息

比如 男女, 年龄,兴趣, 使用的设备,语言,地点

”哪里“ 就是说, 自然搜索, 付费,社交媒体,友情链接等等

"干了啥" 就是说,访问了什么页面,出发了什么事件,购买,联系我们等等.

配合再一起就可以笛卡尔积出很多我们要的信息了。

比如: 大部分男生都是通过自然搜索来购买产品, 女生则更多是广告来购买的. 你下一步就可以针对女性做更多刺激消费了.

除了上面这个特别想说的还有电商。

谷歌对电商有特别对待的. 因为搞网站嘛... 电商是挣钱的丫. 

电商都有一个死流程要走. 

category (规模大一点的是用 search) -> product list -> product detail -> add to cart -> check out -> customer/shipping info -> payment -> review

这个可以算是电商的基本动线了. 如果是广告营销的话可以把 category -> product list 换成广告, product detail 可以换成 landing page (忽悠page)

后半段基本是一样的啦. 

还有一些附加的就是 relate product, coupon/voucher.

最终要分析的就是 啥产品受欢迎, 啥好卖,啥好赚. 我们就是要再里面搞搞花样,那么就能挣点钱啦.

除了卖货,网站要挣钱就是做广告咯. 搞流量,搞内容, 卖曝光, 卖广告

谷歌分析也是有针对这个做一些小 tracing.

比如 content drill (用户读多深), event (play video 等)

好了,有了上面的基本概念,下面说说 setup 咯. 

setup 比较简单,step by step 照着这里做就可以了 

https://developers.google.com/analytics/devguides/collection/analyticsjs?authuser=1

首先去这里拿 Property 号

https://ga-dev-tools.appspot.com/account-explorer/

然后呢放在 head 最上方. 

为什么要 head 最上方呢, 首先 script 用了 async, 所以不会阻塞渲染. (补上个小知识, async 是异步加载马上执行 (可能渲染还没有完), defer 是异步加载然后在渲染完成后 on ready 前执行)

其二是要快执行. 尽可能做到 tracking

<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->

再来就是 tracker, 一个 page 其实可以多个 tracker 的, 但是不知道什么情况要这么复杂.

ga('create', {
  trackingId: 'UA-XXXXX-Y',
  cookieDomain: 'auto',
  name: 'myTracker',
  userId: '12345'
});

创建 tracker, name 是为了之后调用.不放就是 default tracker. 

如果是有登入会员的话, 放 userId 会更好,因为 ga 是无法跨 device 的, 但是有了 userId 就可以识别出来是同一个用户. 

如果是单页面, userId 可能没办法马上获取到. 不过不要担心. 后来补上就可以了,ga 很聪明的, 它会依据同个 session 让开始的 page view 算在 user 头上. refer : https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id

ga('send', 'pageview');
ga('set', 'userId', '12345');

cookieDomain auto, ga 会自动支持 sub domain, 比如 store.stooges.com.my, ga 会设置成 stooges.com.my, localhost 会自动设置成 none

如果我们想分开可以自己 set 过, 不要 auto, refer : https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id

要 send 去另一个 tracker 把名字写在 command 前面就可以了.

ga('clientTracker.send', 'pageview');

在做单页面应用的时候,我们需要修改 page url 和 title 

ga('set', {
  page: '/about',
  title: 'About Us'
}); 
ga('send', 'pageview');

 for tracking, modern browser 都支持 navigator.sendBeacon, 游览器特地 for tracking 的, 以前我们需要监听 send callback 确保谷歌收到了 tracking 才 redirect 用户去下一页.

但有了这个 beacon 就不需要顾虑这个事情了. 我不确定现在 google 

   ga('set', 'transport', 'beacon');

除了 pageview, 还有其它的 hit

event 是最常见的了 https://developers.google.com/analytics/devguides/collection/analyticsjs/events

ga('send', {
    hitType: 'event',
    eventCategory: 'purchase flow',
    eventAction: 'add to cart',
    eventLabel: 'product 1',
    eventValue: 100 // int 哦, decimal 不可以哦
});

category 是你要分析的这个对象的归类, 比如 Videos, Products

action 是对它做了啥,比如 play video, download video, view detail for product

label 是具体的哪个对象, 比如 abc.mp4, product123 

value 是一个价值, 用来衡量这个 action. 指标作用啦

但是你不放也是可以的,看你的管理和分析的方式. 

还有 social (facebook like 等等) 

https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions

https://support.google.com/analytics/answer/6209874

ga('send', {
  hitType: 'social',
  socialNetwork: 'Facebook',
  socialAction: 'like',
  socialTarget: 'http://myownpersonaldomain.com' // 通常是放 facebook page or post
});

report 是通过 custom report dimension social enttiy 来查看

timming hit https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings

这个可以用户测试网站某些地方的速度,比如 place order 啊. submit enquiry form 啦. 速度响应是很重要的,不只是 view, action 响应也要注意. 

ga('send', {
  hitType: 'timing',
  timingCategory: 'JS Dependencies',
  timingVar: 'load',
  timingValue: 3549
});

report 是在 cp behavior -> site speed -> user timing 里面看

接着是 custom dimension 和 metric

dimension 就是维度,或者说一个观察对象特征.

比如一个文章网站,想知道哪个作家最火. 你要怎样 filter 

就是在文章的页面 send pageview 的时候加上作家这个 dimension 信息.

具体做法是先到 cp -> admin -> custom definition -> custom dimension/metric 添加, 然后获取到一个 id, 在调用 send hit 的时候加入 config 里头.

custom dimension 有分 scope level, user, session, hit 特征是属于 访客, 会话或者单次的 hit

顺便提一下, user 就是通过 cookie 就判断的或者 userid, session 就是半小时. hit 就是每次. 

调用的时候先 set, 或者在 send hit 的时候参进去 config 里

ga('set', 'dimension1', 'keatkeat');
ga('send', {
    hitType: 'event',
    eventCategory: 'Video3',
    eventAction: 'play1',
    eventLabel: 'cats.mp4',
    eventValue: 23,
    dimension2: 'dada'
});

metrics 的做法是类似的.

metrics 是指标, 记入的是号码. 比如 discount rate 等等. 也是同样的道理. 在 send hit 的时候我们要记入一些 value 作为分析的指标. 

比如看分析的时候销售员就是 dimension, 销售额就是指标咯. 一个是被分析的特征,一个是好与坏的标准.

debug GA

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna

装这个然后开 F12 开启 chrome dev tool  就可以了. 

Goal 

refer: https://marketingsyrup.com/set-up-event-goals-in-google-analytics/

之前我们 track 了很多 pageview, event 等

这些 track 里面有一些可以被称为 goal, 就是比较关键的 event. 比如购买, 查询, live chat, register 等.

goal 也就是 convertion, 有转化到的意思. 

去 admin -> view -> goals 里头创建 goal, 然后写匹配, 可以说 goal 就是 filter out 一些好的 track.

比如特定的 event, 特定的 pageview 等等. 

在网站里头是不需要说 send 一个 goal 的. 网站只是负责 send event 和 pageview, 然后 cp 来说这个 event/pageview 算不算是一个 goal.

goal 是 per session 计算的, 关键 event 在 session 里触发 2 次, 我们只会看见一个 goal 哦. refer : https://support.google.com/analytics/answer/2679221?hl=en

Remarketing

https://support.google.com/analytics/answer/2444872

https://analytics.google.com/analytics/academy/course/7/unit/4/lesson/1

在 cp setup 就可以了.  (更新: 2020-10-13, 现在改成 activate google signals 就可以了, refer : https://support.google.com/analytics/thread/3709245?hl=en)

admin -> property -> property setting -> Enable Demographics and Interest Reports 打开这个就可以收集到年龄,性别,兴趣

admin -> property -> tracking info -> data collection -> Remarketing & Advertising Reporting Features 打开这 2 个.

有了这个就可以去 admin -> property -> Audiences definition -> 创建 audiences 然后 google ads 就可以用了. 用于 ads display 其实很不错的

Ecommerce

上面有说到 ecom 有些死流程要走. GA 有一个 build-in 的 plugin 可以配合 cp 做 tracking

首先是去 cp 开启 setting, admin -> view -> ecoomerce setting -> 都开 

然后有一个 FUNNEL STEPS 是用于 checkout 的

你有几个 step 就做几个, 比如 customer info -> shipping info ...

0. 基本 set up, 导入 plugin 'ec', setup currency

这个必须在 create tracker 之后写哦 

ga('create', 'UA-xx-1', 'auto');
ga('require', 'ec');
ga('set', 'transport', 'beacon');
ga('set', 'currencyCode', 'MYR');

refer : 

https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#checkout-process (document)

https://enhancedecommerce.appspot.com/ (code example)

1. product impression 产品展现

这里指的是 product list (通常网站有很多 list, 比如 new arrived list, hot list, relate list)

ga('ec:addImpression', {
    name: 'Product 1',
    list: 'Category',
    position: 1
});
ga('ec:addImpression', {
    name: 'Product 2',
    list: 'Category',
    position: 2
});
ga('send', 'pageview');

通过 ec 指令去 setup, 然后发送一个 hit.

hit 是一定要的哦.

这里有一些问题就是, 它属于 pageview 级别, 但是来到一个 page 未必就看完产品丫.

解决方案可以是通过 intersection observer, refer : https://www.twentysixdigital.com/blog/2016/tracking-true-product-impressions-with-google-analytics-enhanced-ecommerce/#blog-article-content

2. product CTR, 当 product list 里面的 product 被点击的时候触发

ga('ec:addProduct', {
    name: 'Product 1',
    position: 1
});
ga('ec:setAction', 'click', {
    list: 'Category'
});
ga('send', {
    hitType: 'event',
    eventCategory: 'Products',
    eventAction: 'view detail',
    eventLabel: 'Product 1'
});

3. product detail view

用户也可以直接进来 product detial page, 比如广告, 分享链接. 所以 pageview 还得记入起来

ga('ec:addProduct', {
    name: productName,
});
ga('ec:setAction', 'detail');
ga('send', 'pageview');

4. add to cart / remove from cart

add

ga('ec:addProduct', {
    name: productName,
    price: 100,
    quantity: 1
});
ga('ec:setAction', 'add');
ga('send', {
    hitType: 'event',
    eventCategory: 'Products',
    eventAction: 'add to cart',
    eventLabel: 'Product 1'
});

remove

ga('ec:addProduct', {
    name: productName,
    price: 100,
    quantity: 1
});
ga('ec:setAction', 'remove');
ga('send', {
    hitType: 'event',
    eventCategory: 'Products',
    eventAction: 'remove from cart',
    eventLabel: 'Product 1'
});

5. checkout

ga('ec:addProduct', {
    name: 'Product 1',
    price: 100,
    quantity: 1
});
ga('ec:setAction', 'checkout', {
    step: 1
});
ga('send', 'pageview');

我觉得用 click event 也是可以得

ga('ec:setAction', 'checkout', {
    step: 3
});
ga('send', {
    hitType: 'event',
    eventCategory: 'Products',
    eventAction: 'place order',
    eventValue: 100
});

6. purchase

我是放在 thank you page (已付款)

ga('ec:addProduct', {
    name: 'Product 1',
    price: 100,
    quantity: 1
});

ga('ec:setAction', 'purchase', {
    id: 'SO-001',
    affiliation: 'Online store',
    revenue: 100,
    shipping: 20,
});
ga('send', 'pageview');

一个完整流程大概是上面这样啦, 感觉还是比较传统得流程. 如果认证要 tracking 细节得话,我个人是觉得不够用的. 可能还得添加更多得 dimensions metrics 进去. 

有一个上面没提到得是 internal promotion 还有 coupon and voucher 关于促销得部分我还没有研究, 但是大致上是一样得. 没有什么特别难得地方. 

原文地址:https://www.cnblogs.com/keatkeat/p/13510647.html