SlideShare a Scribd company logo
User Action Tracking
Google Analytics
1.3.2014

by tureki
“說到要tracking網站使用者行為的時候”
“開發者/工程師都會很傷腦筋”
“因為想到的第一件事情就是要怎麼

存?”
“難道需要建置一個很大的

桶(資料庫)?”

“不停的把會員或遊客每個動作都記錄到

桶內?”
“環境建置,維護成本都很高啊...”
“我只是一個小網站,難道就沒有省時省錢的方式

–哀嚎!

?”
“有的...接下來就要介紹的就是

種省時省錢方法”
Google Analysic(GA)
“GA?不就是放在網站footer就好了

?”
“那是一般用法,其實你還可以更聰明的利用它”
Google Analysic(優點)

✤

免費,申請帳號立即使用!

✤

不需建置和開發伺服器(資料庫)!

✤

不需擔心容量(無底洞)!

✤

不需維護,狂丟資料就對了!
“免費總是要付出一些代價”
Google Analysic(缺點)
✤

資料取出較麻煩(需用API)!

✤

資料只有新增,沒有修改,刪除!

✤

資料有時候會漏掉!

✤

一天資料若過多,需等1,2天才會出現!

✤

你必須了解Google Analysic API
“通常我會將Tracking分成兩類”
User Interface Track (UI Track)
✤

網站介面的tracking!

✤

例如:網頁某個頁面的某個區域的某個按鈕的點擊狀況!

✤

實際情況:A覺得
好,那到底

✤

個按鈕放紅色較好,B覺得放綠色

一個好?!

我們科學點,Track UI!數據會說話!
Backend Track
✤

網站用戶背後分析的tracking!

✤

例如:網站User看了什麼,買了什麼個商品等!

✤

為了做Data Mining,用戶興趣等!

✤

實際情況:會員最喜歡

✤

後端使用如:(php,python etc.)將資料push給GA

一個分類?最喜歡

一個商品等!
“在實做前,

還必須了解...”
Track Page View(GA)
舉例
✤

其實把GA的追踪碼放到網頁下方,就是在執行Track Page
View 個動作

GA會將該頁面的url和title給記錄起來。
如果網址是/user/register/index.html!
!

那麼GA就會將它變成:!
user/!
├── register/!
│ ├── index.html!
!

也就是說 / 號GA會自動將內容會變成目錄層級(/不能亂用)。
“重點來了”
“如果Track Page View 的資料能自己DIY不就很棒了?”
“沒錯接下來就是要用GA-API來傳送你要的資料”
https://developers.google.com/analytics/devguides/collection/
analyticsjs/

(ps:由於GA已有新版Tracking Code,往後的範例都會新版為主)
分開GA
為了不破壞原來的GA,通常我的做法會將GA分開
舉例
✤

UA-XXXXX-01 -> 網站一般GA!

✤

UA-XXXXX-02 -> UI Track GA(lab)!

✤

UA-XXXXX-03 -> UI Track GA(正式)!

✤

UA-XXXXX-04 -> Backend Track GA(lab)!

✤

UA-XXXXX-05 -> Backend Track GA(正式)
我個人是覺得

樣才好管理,!

!

測試時候就用lab的Tracking Number,!
!

正式環境就記錄在正式Tracking Number,!
!

是為了防止GA的目錄資料結構被破壞,!
!

你要記得GA只能新增,沒有修改和刪除
一個頁面是容許建立兩個實例,以下是ga給的範例:!
<script>!
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){!
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),!
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)!
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');!
!
ga('create', 'UA-XXXXX-1', 'your.domain');!
!
</script>!

!

一個頁面是同時可以建立多個實例的,如:!
var ga_1 = ga('create', 'UA-XXXXX-1', 'your.domain');!
var ga_2 = ga('create', 'UA-XXXXX-2', 'your.domain');
開始實做 UI Track
範例一
情境:首頁有個圖片區域,到底大圖點擊率高,還是小圖多?
小圖
大圖

小圖
小圖

大圖:!
/index/img-panel/large/[img]!
小圖:!
/index/img-panel/small/[img]
當IMG被被點擊時候(JS)
var ga_ui_track = ga.create('UA-XXXXX-02', 'auto', {'name': 'UA-XXXXX-02'});!
ga_ui_track.send('pageview',{page:"/index/img-panel/left/img"});!
!
你在GA的後台就能即時看到,如圖:

修改成功!!

!
聰明的你會發現!
!
其實設計PATH(/index/img-panel/left/img)才是重點,!
!
不同的需求會有不同的目錄結構
為了要讓追踪變得簡單,我的做法是將追踪的track放在html內!
<img src="small.jpg" track="/index/img-panel/small/img"/>!
!
用jQuery偵測全域的attr:!
var ga_ui_track = ga.create('UA-XXXXX-02', 'auto', {'name': 'UA-XXXXX-02'});!
!
jQuery('body').on('click', '[track]', function(e) {!
!
!
var _str_track = jQuery(this).attr("track");!
!
!
ga_ui_track.send('pageview',{page:_str_track});!
!
});
你可到以下網址取得範例一的Testing Code!
!

https://gist.github.com/tureki/9303954!
!

因為之後的實做邏輯都一樣,就不再製作了
使用GA後台
若要找大圖,就行為->網站內容->搜尋下large/img,如圖:

注意,日後GA後台容不容易找到你要的資

,都取決你的PATH怎麼設計!
範例二
情境:如果介面是全域如header,該怎麼設計?

login
header

假設是登入按鈕!
!

可以考慮:/common/header/menu/[btn:login]
我會將頁面常出現的UI都放在common內!
!

但是

樣設計雖然能將取得header的數據!

!

但沒辦法取得首頁header被點擊的狀況!
!

所以我會首頁header被點擊的時候,動態將資料從!
/common/header/menu/[btn:login]!
變!
/index/common/header/menu/[btn:login]!
!

在後台如果要取全部資料就下 /common/header/!
!

要單獨取首頁就下 /index/common/header/!
!

至於要怎麼判斷

是那一頁和設計PATH就是你的功課了。
“記得!PATH很重要!”
如何測試和Debug?
✤

用你的LAB Tracking Number!

✤

用GA官方插件!

✤

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

✤

用GA後台的即時預覽
開始實做Backend Track
基本上Backend Track和UI Track是一樣的,!
!

關

在於PATH的設計!
!

還有記錄方式在後端!
!

本範例採用PHP:!
!

https://github.com/thomasbachem/php-ga
範例一
情境:會員在看首頁,可以將PATH設計成!
/member/{Member ID}/{Action}/{Object}!
也就是!
/member/1/view/page/index!
!

遊客在看首頁!
/guest/view/page/index
範例二
會員成功

冊+來從那一頁點過來?!

/member/1/register/(來源)!
!

你可以設計成!
$str = "/member/1/register/(from:".$_SERVER['HTTP_REFERER'].")";!
!

也就是說,你愛怎麼組合都是由你在決定
範例三
會員買了一個商品,假設商品有分類,商品也有ID。!
/member/{Member ID}/buy/item/{CATALOG ID}/{ITEM ID}!
也就是!
/member/1/buy/item/2/3!
!

PHP後端使用的範例請看:!
https://github.com/thomasbachem/php-ga!
!

重點就在:!
$tracker->trackPageview("/member/1/view/page/index", $session,
$visitor);
GA後台搜尋
若要找分類2商品,搜尋就下!
/item/2/!
!

如果要找ITEM ID 3,搜尋就下!
/item/2/3/!
!

注意:GA的search支援regex,所以如果你會正規,東西更好找!
regex URL!
!

https://support.google.com/analytics/answer/1034324?hl=en
Guest的問題
“遊客可以做到像會員那樣的記錄

?”
“可以的,只是問題是你想怎麼做?GA只是個
人是你。”

桶,用它的
“

裡給個簡單的思路:”
讓guest有個永久的Cookie,PATH設計成!
/guest/{COOKIE}/view/page/index!
!

當guest變會員或登入時,將guest的cookie和member ID mapping起來!
!

你就會知道

個會員在還沒登入和

冊前做了什麼事情。!

!

重點在Mapping的資料你要

存起來,因為GA的資料新增後是無發修改的,!

!

也就是你無法將之前記錄的!
/guest/{COOKIE}/view/page/index!
變成!
/member/{member ID}/view/page/index!
!

mapping cookie的資料至於要

存在那?!

!

我個人目前是用Elasticsearch

存。
GA的基準
新版有提供自訂!
!

Custom Dimensions and Metrics,!
!

也就是你能自訂點擊量!
!

各位可以自行摸索
最後
“

種方法已實用近2年,以下Backend Track的

已免費

存過億...

存量”
我個人覺得以上做法長久之計只適合小型公司!
!

有資源還是建議用正常的方式去做大數據分析!
!

畢竟現在技術成熟!
!

AWS也有提供類似的服務
“沒有最棒的方法,只有最適合你的方法”!
“根據你的環境,選擇最適合現在的做法才是王道”
“END”

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

User Action Tracking - Google Analytics