如何使用Google Analytics在使用多个子域时跟踪ASP.Net MVC Web应用程序 [英] How to track ASP.Net MVC web app using Google Analytics when multiple subdomains are used
问题描述
- 这个ONE Webapp提供许多不同的功能网站(种)。我的意思是代码只是一个,但它为我们的100多个客户运行,他们都看到他们的网站不同(如果他们都有他们单独的网站)
- 但在后端它的所有处理来自只有一个代码。我们有点读取子域名,并根据该域名加载网站/客户特定的BLOB,并加载特定客户的特定网站。
- .abc.xyx.com - 客户网站1
- B.abc.xyz.com - 客户网站2
- C.abc.xyz .com - 客户网站3
-
我知道所有网站都有相同的代码,因此所有网站都有相同的Google Analytics(分析)跟踪代码。
例如:
现在我的一位客户要求将Google分析添加到他们的网站。所以我去了谷歌分析,并添加了 A.abc.xyx.com 网站。它生成了一个JS标签。
我得到了代码并将它添加到我的头标记中。并发布了该网站。
问题:该标签现在出现在所有客户的网站上。
例如:
如果A.abc.xyz.com - 打开5次
$ b。b如果B.abc.xyz.com - 打开3次
如果C.abc.xyz.com - 打开2次
Google分析显示活动连接= 10。 我的假设是自创建A.abc.xyz.com标签以来,它只会跟踪该标签。但它跟踪所有的网站。 为何如此??? p> 我可以尝试阅读在浏览器中打开的子域,并且仅在其跟特定子域匹配时才添加跟踪脚本。但是明天如果其他客户要求他们的独立分析,我将如何管理它。 问题:如何确保只有A.abc .xyx.com得到跟踪 您可以为每个域创建一个子文件夹,例如 / custom / A
/ custom / B
等。然后在里面放置一个分析视图,例如
/custom/A/analytics.cshtml
然后在你的布局页面中:
string domain =逻辑在这里取得域名;
if(File.Exists(Server.MapPath(string.Format(/ custom / {0} /analytics.cshtml,domain))))
{
Html.RenderPartial(string .Format(/ custom / {0} /analytics.cshtml,domain));
}
如果有客户的文件存在,它不会。
Brief Introduction of ASP.Net MVC 5 webapp I work on
- This ONE Webapp serves many different websites (kind of). I mean code is just ONE but it runs for our 100's of customers and they all see their website differently (as if they all have their separate website)
- But in the back end its all handled from the just ONE code. We kind of read the subdomain and based on that we load the website/customer specific BLOB and load website specific to a particular customer.
- Long story short if I STOP the IIS for my standalone webapp all the website will stop.
URl's for the website looks like below:
Example:
- A.abc.xyx.com - website for customer 1
- B.abc.xyz.com - website for customer 2
- C.abc.xyz.com - website for customer 3
Now one of my customer is asking for google analytics to be added to their website. So I went to google analytics and added A.abc.xyx.com website. It generted one JS Tag.
I got the code and added it in my Head Tag. And published the website.
Problem: That tag is now present in all the customer's website.
For example:
if A.abc.xyz.com - opened 5 times
if B.abc.xyz.com - opened 3 times
if C.abc.xyz.com - opened 2 times
The google analytics shows me that active connection = 10.
I know that all the websites have the same code and thus all have the same Google analytics Tracking code.
My Assumption was since I created the tag for A.abc.xyz.com, it will only track that. But its tracking all the websites. WHY SO???
Workaround:
I can try to read the subdomain that is getting opened in the browser and CONDITIONALLY add the Tracking script only when its matches a particular subdomain. But tomorrow if some other customer asks for their standalone Analytics how will I manage it.
Question: How to make sure that only A.abc.xyx.com gets tracked
You could create a sub folder for each domain e.g.
/custom/A /custom/B
etc. Then put a partial view inside there for the analytics e.g.
/custom/A/analytics.cshtml
Then in your Layout Page:
string domain = "logic to get domain here";
if (File.Exists(Server.MapPath(string.Format("/custom/{0}/analytics.cshtml", domain))))
{
Html.RenderPartial(string.Format("/custom/{0}/analytics.cshtml", domain));
}
That way if there is a file for that customer if will include it, otherwise it won't.
这篇关于如何使用Google Analytics在使用多个子域时跟踪ASP.Net MVC Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!