如何在Google Analytics中实施唯一自定义指标

时间:2021-11-27 15:14:29

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. I've been asked to setup Google Analytics for this website and create a couple of reports for it.

考虑一个向不同学校提供服务的Web应用程序,即每个登录凭据由三部分组成:学校代码,用户名和密码。我被要求为此网站设置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 events and send them regardless of page load (it's a Single Page Application anyway). 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. 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 Dimensions和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]

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? i. e., 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.

为了使问题更容易理解,请考虑建立一个销售不同类型产品的网店。如何在GA中创建一个报告,显示一段时间内看到过多少个独特产品的页面?一世。例如,如果今天看到产品X的页面,它将在报告中将今天的栏增加1,无论它看到多少次。

3 个解决方案

#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:

你第一次看的任务很简单,但实际上 - 事实并非如此。你可以尝试做什么:每次,当用户登录时,发送带参数的事件:

  • Category: unique school identifier
  • 类别:独特的学校标识符

  • Action: whatever you want (for example, hashed login or user ID)
  • 操作:您想要的任何内容(例如,哈希登录或用户ID)

  • Label: empty.

After simulation data looks like:如何在Google Analytics中实施唯一自定义指标 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:

这种方法有什么不好:

  1. You can only choose one separate day to analyse, how many schools were active. So you can't choose range like May 1 - May 5 and get report with count of active schools per day. You should manually choose five 1-day periods(May 1- May 1, May 2 - May 2 and so on) and manually grab count of rows in events table for each day.
  2. 您只能选择一个单独的日子来分析,有多少学校是活跃的。因此,您无法选择5月1日至5月5日的范围,并获得每日活跃学校数量的报告。您应手动选择五个1天期间(5月1日至5月1日,5月2日 - 5月2日等),并手动获取每天事件表中的行数。

  3. Unfortunately, you can't access to metric "Count of rows" in Google Analytics interface and show it at custom report. This may available at Google Analytics API(require a lot of programming, not sure that it's what do you need).
  4. 很遗憾,您无法在Google Analytics界面中访问指标“行数”并在自定义报告中显示。这可以在Google AnalyticsAPI上获得(需要大量编程,不确定它是否是您需要的)。

#2


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的交易,那么当天就会有当天有活动学校的交易数量。

#3


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). 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. 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.

让网页包含一个指向文件的iframe,该文件的名称是日期+学校名称(或您可能需要的其他粒度)。让404处理程序创建(不返回)具有请求名称但不调用GA的空白HTML文件,但返回包含GA调用的HTTP代码200和HTML。这样,每个学校每个日期只会调用一次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 (e.g. Google's).

    客户端的javascript Date对象可能是错误的,最好从可靠服务器(例如Google)的Date:头获取当前时间。

  • 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.

    也可以在所有脚本完成客户端的情况下实现这种机制,尽管它使事情变得更复杂一些。如果你完全没办法在服务器端添加脚本,请告诉我。

#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:

你第一次看的任务很简单,但实际上 - 事实并非如此。你可以尝试做什么:每次,当用户登录时,发送带参数的事件:

  • Category: unique school identifier
  • 类别:独特的学校标识符

  • Action: whatever you want (for example, hashed login or user ID)
  • 操作:您想要的任何内容(例如,哈希登录或用户ID)

  • Label: empty.

After simulation data looks like:如何在Google Analytics中实施唯一自定义指标 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:

这种方法有什么不好:

  1. You can only choose one separate day to analyse, how many schools were active. So you can't choose range like May 1 - May 5 and get report with count of active schools per day. You should manually choose five 1-day periods(May 1- May 1, May 2 - May 2 and so on) and manually grab count of rows in events table for each day.
  2. 您只能选择一个单独的日子来分析,有多少学校是活跃的。因此,您无法选择5月1日至5月5日的范围,并获得每日活跃学校数量的报告。您应手动选择五个1天期间(5月1日至5月1日,5月2日 - 5月2日等),并手动获取每天事件表中的行数。

  3. Unfortunately, you can't access to metric "Count of rows" in Google Analytics interface and show it at custom report. This may available at Google Analytics API(require a lot of programming, not sure that it's what do you need).
  4. 很遗憾,您无法在Google Analytics界面中访问指标“行数”并在自定义报告中显示。这可以在Google AnalyticsAPI上获得(需要大量编程,不确定它是否是您需要的)。

#2


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的交易,那么当天就会有当天有活动学校的交易数量。

#3


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). 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. 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.

让网页包含一个指向文件的iframe,该文件的名称是日期+学校名称(或您可能需要的其他粒度)。让404处理程序创建(不返回)具有请求名称但不调用GA的空白HTML文件,但返回包含GA调用的HTTP代码200和HTML。这样,每个学校每个日期只会调用一次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 (e.g. Google's).

    客户端的javascript Date对象可能是错误的,最好从可靠服务器(例如Google)的Date:头获取当前时间。

  • 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.

    也可以在所有脚本完成客户端的情况下实现这种机制,尽管它使事情变得更复杂一些。如果你完全没办法在服务器端添加脚本,请告诉我。