如何从动态生成的ASP.NET MVC页面调用Google Analytics脚本

时间:2021-11-14 15:21:30

I have a number of cases in my ASP.NET MVC web app where I return a dynamic result (ContentResult which returns an rss feed in this case) from a controller action method rather than a view. In these cases how can I implement Google Analytics tracking?

我在我的ASP.NET MVC Web应用程序中有很多案例,我从控制器操作方法而不是视图返回动态结果(在这种情况下返回rss提要的ContentResult)。在这些情况下,我如何实施Google Analytics跟踪?

1 个解决方案

#1


0  

You cannot include JavaScript-based tracking into RSS file, because as far as I can see from specification, there is no way to include JavaScript code/link into it.

您不能将基于JavaScript的跟踪包含到RSS文件中,因为就我从规范中看到的情况而言,无法将JavaScript代码/链接包含在其中。

As Matt explained, you need to use measurement protocol from Google or something similar and perform web request from your MVC action. This, however, will increase load on your web server. There are 2 other disadvantages with server-side tracking:

正如Matt所解释的那样,您需要使用Google或类似的测量协议,并从您的MVC操作中执行Web请求。但是,这会增加Web服务器的负载。服务器端跟踪还有其他两个缺点:

  1. You will not be able to track additional information with this method like visit duration, bounce rate etc.
  2. 您将无法使用此方法跟踪其他信息,例如访问持续时间,跳出率等。

  3. RSS is frequently downloaded by automatic tools and you stats will be very misleading.
  4. RSS经常被自动工具下载,你的统计数据会非常误导。

You should consider those limitations when implementing your server-side tracking.

在实施服务器端跟踪时,您应该考虑这些限制。

#1


0  

You cannot include JavaScript-based tracking into RSS file, because as far as I can see from specification, there is no way to include JavaScript code/link into it.

您不能将基于JavaScript的跟踪包含到RSS文件中,因为就我从规范中看到的情况而言,无法将JavaScript代码/链接包含在其中。

As Matt explained, you need to use measurement protocol from Google or something similar and perform web request from your MVC action. This, however, will increase load on your web server. There are 2 other disadvantages with server-side tracking:

正如Matt所解释的那样,您需要使用Google或类似的测量协议,并从您的MVC操作中执行Web请求。但是,这会增加Web服务器的负载。服务器端跟踪还有其他两个缺点:

  1. You will not be able to track additional information with this method like visit duration, bounce rate etc.
  2. 您将无法使用此方法跟踪其他信息,例如访问持续时间,跳出率等。

  3. RSS is frequently downloaded by automatic tools and you stats will be very misleading.
  4. RSS经常被自动工具下载,你的统计数据会非常误导。

You should consider those limitations when implementing your server-side tracking.

在实施服务器端跟踪时,您应该考虑这些限制。