When to Track on the Client vs. Server
Knowing how to consolidate events and effectively use properties
can make the implementation easier. However, we are still faced with the choice as to where to implement that tracking—on the client or on the server.
While it’s easy to just do everything on the client or everything on the server, in reality it isn’t that simple. Depending on what you want to learn about your users, there are types of events that are only available on the client. On the other hand, there are many common pitfalls on the client, such as
This week, we’ll explore the differences between the client and the server, a quick guide to determining where certain events should be implemented, and explain the trade offs in more detail so you can make an intelligent final call.
A Quick Note on Ad Blockers
We talk about ad blockers and suggest the alternative of collecting the analytics data (by making the same call on the server). Kindly note that we, by no means, condone gathering data from users who, through the act of using ad blockers, wish to prevent their data from being collected.
We should respect the privacy of our users and their choice of using ad blockers. If there is something that must be tracked on the client, one suggestion is to nicely ask your users to disable ad blocking so you can provide them a more personalized browsing experience.
What exactly is tracking on client and server?
To help understand the nuances and trade offs of tracking on client vs. server, here are basics of their technical capabilities.
On the web, a client is your browser (or mobile, though this post really details trade offs specific to browsers)—what you use to navigate the Internet. The server is a computer that returns web pages to be rendered in your browser. Learn more about web architecture here.
A: Whenever any user goes to a website, a request is made to the web server to retrieve the necessary files (HTML, css, js) to render that page in the browser. This link, while not directly related to either client or server side tracking, shows that you can mimic a client-side call on the server by sending the necessary info from the client to the server then sending the call on the server.
B: This is tracking on the client: sending tracking data from the browser to the analytics service. Since the call is made from the browser, client-side tracking gives you easy access to a lot of contextual browser (and, therefore, the user) information. These include:
- cookies: these are a mechanism for websites to remember stateful information or to record the user’s historic browsing activity. You’ve probably heard of cookies being used to manage shopping carts, whether or not you’ve logged in, etc.
- UTM parameters: these parameters are in every digital marketer’s toolkit. Their utility is outside the scope of this post, but check out this great introduction to them here. Basically, they’re these semantic parameters included in the URL that helps analytics tools know what ad campaign or channel a user went through to land on the destination site.
- IP address: IP address is a numerical label assigned to each device connected to the Internet. From marketers’ perspectives, it’s useful to learn the geographic location of the user. There are many analytics tools or data enrichment services that’ll show you the location based on their IP address.
- User agent: Within the context of the Internet, the user agent represents the device and browser specifications of the user. This is great to learn about what devices your users use while on your site.
C: This is tracking on the server: sending tracking data from your web server to the analytics service. The web server’s main role is to handle “HTTP requests”, which is the underlying protocol upon which the web is built. As such, the server only has access to information in the request, which include (but are not limited to):
- Headers: This is mostly information for machines to direct traffic and doesn’t provide that much use to humans
- Request Body: This is the main part of the request. In the majority of cases, this is where you would put data if you want to send it via HTTP.
Note that the information on the server side is limited to the request, which is more limited than what you can get from the client. In order to send a server-side call that contains UTM param information, you’d need some client-side logic that will parse the parameters, send it via C to the server, then send it from the server to the analytics service.
When do I track on client and server?
We’ve made a guide flow chart, depending on your circumstances, that’ll recommend whether to implement the event in question on the client or on the server.
Before we dive in, there are three main dimensions you should consider: your analytics objective (what do you want to learn?), available engineering resources, and the privacy concerns of your target users.
- Analytics Objective: Some events or tools, due to their nature, must be implemented on the client. For example, session recording/heat mapping tools and ad pixels leverage too much of the browser to be able to replicate on the server.
- Engineering Resources: Most things that can be tracked on the client (with the exception of client-only events) can also be tracked on the server. However, since some information on the client is more readily accessible (e.g. IP address, user agent, utm parameters), tracking the same thing on the server may take additional engineering resources.
- Privacy Concerns: the privacy concerns of your users indicate the likelihood they would have Ad Block enabled for their browsers (often in the form of a Chrome extension). Ad Block prevents any analytics data to leave the browsers, meaning that you could be missing data from parts of your user base.
That being said, keep in mind that the below is just a guide! It’s neither definitive nor black and white because there are situations where you make the opposing case given enough thought and engineering resources.
What are the trade-offs?
The big trade off is context (or the amount of data you can easily access and gather) vs. reliability (or how much control you have over the actual sending of the data).
To better understand why, let’s dive into the technical details that separate client and server.
The client, being that it’s the browser, has easy access to user specific attributes, such as cookies, IP address, user agent, referrer, and UTM parameters. This means that if you track on the client, you easily can collect and track all of these contextual pieces of information. Some common business use cases for tracking these pieces include:
- send targeted marketing messages based on users’ locations
- learn the breakdown of your users based on mobile, desktop, tablet
- determine marketing campaigns drive traffic and conversion via UTM parameters
However, the downside about tracking in the client is that you have less control. The end user can enable an ad blocker, which can punch a hole in your analytics data. The browser also has its own unique behaviors such as page unloading (when you click a link on a site and the browser begins loading the next page) that can sometimes interrupt any “in-flight” outbound analytics requests (more on troubleshooting for this specific browser case). Therefore, we usually suggest tracking on the server. It tends to be more reliable.
These are the kinds of events that we recommend sending via the server:
- “Offsite” events: This just means events that aren’t tied to a user behavior that occurs on your website or an event that is the result of a calculation based on your production database. An example of this would be our nightly cron job that calculates API usage across our customer base, then sends server side
.track()
calls. - Tracking revenue (or other sensitive events): Revenue figures (though should be captured by your billing system) should be sent on the server, since they’re sensitive and discrepancies from ad blockers or browser mishaps would be frustrating to debug.
- Mission critical events: If you’re using email or marketing automation tools that rely on events to trigger high-value emails, it’s best to keep these events on the server side. It would be a bummer to have a customer miss out on a coupon or re-engagement email due to ad block.
However, there are some reasons why you’d want to stay on the client. Since the server can’t easily access the information in the browser, you’ll need additional engineering resources to mimic the same call on the server. For example, you would need client-side logic to capture the UTM params, send it to the server, and then have the server send it to your analytics service. Since analytics data is useful directionally and for trends, many times the convenience of tracking UTM params, ip address, etc. on the client outweigh the possibility of losing data a small percentage of data here and there to an ad blocker or weird browser behavior.
Therefore, the rest of the decisions (aside from the first three steps) in the flow chart can be done on either client or server side (though we strongly encourage tracking revenue and sending mission critical events on the server side).
We hope that this provides some insight as to the trade offs of tracking certain events on the client vs. on the server.
Do you have a different approach to deciding what goes on the client or server? We’d love to hear it on Twitter!
相關推薦
When to Track on the Client vs. Server
Knowing how to consolidate events and effectively use properties can make the implementation easier. However, we are still faced with the choice a
Should I instrument data collection on the client or server? Documentation
One of the most common questions we receive is: “Should I use one of your client-side libraries or one of your server-side libraries?”This is such an impor
Form is submitted when I click on the button in form. How to avoid this?
原來button 沒加 type 屬性,會變成 submit @[email protected]; 太久沒寫網頁,這個變化真大。 A button element with no type attribute specified represents the same thing as a butto
Warning: date(): It is not safe to rely on the system's timezone settings.
bsp ron notice zone asi 警告 family one str PHP調試的時候出現了警告: It is not safe to rely on the system解決方法,其實就是時區設置不正確造成的,本文提供了3種方法來解決這個問題。 實際上,
Enable SMB2 on the Client
lse not ould sys pen like isa tar chan HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanWorkstation edit DependOnService and ad
php Warning phpinfo It is not safe to rely on the system
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use
方法一:在程式碼中加入 date_default_timezone_set("PRC");即可 date_default_timezone_set('PRC')表示設定中國時區 方法二 :在配置檔案php.ini中修改配置 在php.ini里加上找到date.timez
凜冬之翼---關於時區的PRC和UTC的設定It is not safe to rely on the system's timezone settings
今天再引入jpgraph庫的時候遇到了一個時區的問題,先是報錯: It is not safe to rely on the system’s timezone settings 就是說你的時區不對。 網上提供了兩種方法: 1.再php.ini中把timezone=前面的分號去掉再改
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use
方法一:在程式碼中加入 date_default_timezone_set("PRC");即可 date_default_timezone_set('PRC')表示設定中國時區 方法二 :在配置檔案php.ini中修改配置 在php.ini里加上找到date
A Virtual Jewish Nation May Teach the World How to Live on the Cloud
A Virtual Jewish Nation May Teach the World How to Live on the CloudWe’re all familiar with “the cloud.” But have heard about “cloud nations”?If you ask fu
MIT undergraduates to embark on The Quest
Each year MIT professors invite thousands of undergraduates into their labs to work on cutting edge research through MIT’s Undergraduate Research Opportuni
Can I use the Profile API on the client-side? Documentation
For security reasons, we require the Profile API only be used server-side. The Profile API allows you to look up data about any user given an identifier (e
It is not safe to rely on the system's timezone settings
ted mil ext app eight upload 大神 hose 老師 在寫php文件上傳程序時有時會出現這樣的警告: Upload: 屏幕截圖2014-09-28_160214.png Type: image/png Size: 66.847656
How to edit codes on the server which runs jupyter notebook using your pc's bwroser
repl lan HA sin AR make you 技術 des If you don‘t use jupyter, you may have to edit your source codes on your pc and upload them to your se
PHP錯誤:SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
升級 文件中 sta 否支持 sha2 authent lte 子句 bubuko 使用PHP連接MySQL 8的時候,可能會發生如標題所示的錯誤: SQLSTATE[HY000] [2054] The server requested authentication me
mysql 8.0 錯誤The server requested authentication method unknown to the client
新版 span sql class ring mysql 安裝 line requested cati mysql 安裝了最新版本8.0.11後創建用戶並授權後,授權的用戶連接數據庫提示 The server requested authentication method
If you want to allow applications containing errors to be published on the server
serve enable errors websphere ebsp ror HERE The win If you want to allow applications containing errors to be published on the server, en
phpmyadmin連線MySQL8.0報錯#2054 - The server requested authentication method unknown to the client
發生這種錯誤,是由於MySQL 8預設使用了新的密碼驗證外掛:caching_sha2_password,而之前的PHP版本中所帶的mysqlnd無法支援這種驗證 有幾種方法:1.升級PHP版本,PHP7.xx有支援MySQL8.0的外掛認證 2.修改配置檔案my.cnf 使資料庫啟用相容的
解決IIS7執行ASP提示錯誤:An error occurred on the server when processing the URL. Please contact the system administrator
在WINDOWS7或SERVER2008上安裝了IIS7.5,除錯ASP程式時出現以下錯誤: An error occurred on the server when processing the URL. Please contact the system administrator
HOW TO RUN YOUR WEB SERVER AND MQTT WEBSOCKETS BROKER ON THE SAME PORT
I was just asked how one can deploy a similar setup as the iot.eclipse.org MQTT sandbox, where MQTT over WebSockets is available on por