[英]How to implement Unique Custom Metric in Google Analytics
Consider a web application that gives out services to different schools, that is, each log in credentials consist of three parts: school code, username and password. 考虑一个向不同学校提供服务的Web应用程序,即每个登录凭据由三部分组成:学校代码,用户名和密码。 I've been asked to setup Google Analytics for this website and create a couple of reports for it.
我被要求为此网站设置Google Analytics并为其创建几个报告。
There's one particular report which I still couldn't figure out how to implement: The number of active schools per date. 有一个特别的报告,我仍然无法弄清楚如何实施:每个日期的活跃学校数量。 An active school is one which some student of it has used the website.
一个活跃的学校是其中一些学生使用该网站的学校。 Here's my approach so far:
到目前为止,这是我的方法:
I decided to incorporate event
s and send them regardless of page load (it's a Single Page Application anyway). 我决定合并
event
并发送它们而不管页面加载(无论如何它都是单页应用程序)。 I would then send an event for each log in including the school code. 然后我会为每个登录发送一个事件,包括学校代码。 To keep the question short, no matter what I did I could not find a way to count the correct number of active schools.
为了保持简短的问题,无论我做了什么,我都找不到计算正确数量的活跃学校的方法。 I've tested with
Unique Events
, Custom Dimensions
and Custom Metrics
. 我已经使用
Unique Events
, Custom Dimensions
和Custom Metrics
进行了测试。 In case of Unique Events
, sessions disturb the results and in case of Custom Metrics
, there's no such thing as "Unique Custom Metric"! 在
Unique Events
情况下,会话会影响结果,如果是Custom Metrics
,则不会出现“独特的自定义指标”!
The worst part is that each new solution I would want to test takes me a day! 最糟糕的是,我想要测试的每个新解决方案都需要我一天! And it's driving me crazy (patience is not my specialty).
它让我发疯(耐心不是我的专长)。
[UPDATE] [UPDATE]
To make the question easier to understand, consider having a web-shop that sells different kinds of products. 为了使问题更容易理解,请考虑建立一个销售不同类型产品的网店。 How can you create a report in GA that shows how many unique products' pages have been seen for a period of time?
如何在GA中创建一个报告,显示一段时间内看到过多少个独特产品的页面 ? ie, if product X's page has been seen today, it will increment today's bar by one in the report, regardless of how many times it's been seen.
也就是说,如果今天看到产品X的页面,它将在报告中将今天的栏增加1,无论它看到多少次。
your task in a first look is pretty simple, but it fact - it's not. 你第一次看的任务很简单,但实际上 - 事实并非如此。 What you can try to do: each time, when user logged in, send event with parameters:
你可以尝试做什么:每次,当用户登录时,发送带参数的事件:
After simulation data looks like: 模拟数据看起来像:
As event labels are unique for each school, then count of active schools per day - is count of rows at table with events(marked at image).
由于事件标签对于每所学校都是唯一的,因此每天活跃学校的数量 - 是带有事件的桌子上的行数(标记为图像)。
What's bad in this approach: 这种方法有什么不好:
In the standard data layout this cannot be precalculated as you are in essence counting the number of unique dimensions on the date. 在标准数据布局中,这不能预先计算,因为您实际上是在计算日期上唯一维度的数量。
But there are two exceptional dimensions that require joining data to build their normal views: userId
and transactionId
. 但是有两个特殊维度需要连接数据来构建其正常视图:
userId
和transactionId
。
So you could either give everyone in one group the same user id or a shared transaction. 因此,您可以为一个组中的每个人提供相同的用户ID或共享事务。
As an example, if you create a transaction with an id of Date+schoolId whenever a use logs in, there will be as many transactions on any day as there are active schools on that day. 例如,如果您在每次使用登录时创建ID为Date + schoolId的交易,那么当天就会有当天有活动学校的交易数量。
You need some tiny persistence on the server side. 你需要在服务器端有一些小的持久性。
Let the web page include an iframe
pointing to a file whose name is the date + school name (or other granularity as you may need). 让网页包含一个指向文件的
iframe
,该文件的名称是日期+学校名称(或您可能需要的其他粒度)。 Let the 404 handler create (not return) a blank HTML file with the requested name that doesn't call GA, but returns HTTP code 200 and HTML that includes the GA calls. 让404处理程序创建 (不返回)具有请求名称但不调用GA的空白HTML文件,但返回包含GA调用的HTTP代码200和HTML。 This way the GA-API will be called only once per school per date, so you'll get the GA report you're looking for.
这样,每个学校每个日期只会调用一次GA-API,因此您将获得您正在寻找的GA报告。
Points to note: 注意事项:
Better to keep the files in a separate directory with their own .htaccess
(or your web server's specific equivalent) and 404 handler, to avoid conflicts with the site's code. 最好将文件与他们自己的
.htaccess
(或您的Web服务器的特定等效文件)和404处理程序保存在一个单独的目录中,以避免与站点代码冲突。
You should probably clean those files once in a while. 您应该偶尔清理一下这些文件。
The client's javascript Date
object might be wrong, it is better to get the current time from the Date:
header of a reliable server (eg Google's). 客户端的javascript
Date
对象可能是错误的,最好从可靠服务器的Date:
头获取当前时间(例如Google)。
It is also possible to implement this mechanism with all scripting done client side, though it makes things a bit more complicated. 也可以在所有脚本完成客户端的情况下实现这种机制,尽管它使事情变得更复杂一些。 Let me know if you have absolutely no way of adding scripts on the server side.
如果你完全没办法在服务器端添加脚本,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.