如何从代码触发 Google Analytics? [英] How to trigger Google Analytics from code?

查看:24
本文介绍了如何从代码触发 Google Analytics?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用从我的网站读取一个 (html) 文件,我想使用 Google Analytics 跟踪对该文件的访问.由于在读取文件时不会执行 GA Javascript,因此不会对其进行跟踪.有没有办法直接从代码触发 GA,或者从 .NET 应用程序执行 Javascript 而不添加一堆依赖项?

My app reads an (html) file from my website, and I would like to track accesses to that file using Google Analytics. As the GA Javascript does not get executed when reading the file, it is not tracked. Is there a way to trigger GA directly from code or alternatively, to execute the Javascript from a .NET app without adding a bunch of dependencies?

推荐答案

Google Analytics 的工作原理是通过 javascript 向 Google 的服务器发出网络请求.如果您想以编程方式执行此操作,您只需自己发出此 Web 请求.当您在浏览器中加载页面时,我会使用 Fiddler 或 FireBug 来捕获请求的样子.然后您可以在您的 .Net 应用程序中使用相同的 URL.

Google Analytics works by making a webrequest through javascript back to Google's server. If you want to do this programmatically, you just have to make this web request yourself. I would use Fiddler or FireBug to capture what the request looks like when you load the page in your browser. Then you can use that same URL in your .Net app.

这篇关于如何从代码触发 Google Analytics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆