Google has multiple options to generate ag code script depends on what you tracking:
1)A single domain e.g site.com
2)One domain with multiple subdomains e.g site.com/something.site.com
3)Multiple top-level domains e.g site.ch/site.fr
but Microsoft.Web.Helpers
has only two google methods:
GetGoogleAsyncHtml(string webPropertyId);
GetGoogleHtml(string webPropertyId);
So there is no way to control options i described above.
Is it big deal if i would have site with One domain with multiple subdomains(second options)
but at the same time i wou开发者_StackOverflowld use one of methods above, or better just to get script form google in such case and forgot about that helper?
p.s.
I just find out that method @Analytics.GetGoogleAsyncHtml()
returns exactly the same ga script as google A single domain e.g site.com
does. So looks like that helper does not generate another two types.
You can create your own helper that will do the job that you want. This is what i have done on my side to support Piwik. Just take the following example and edit it to support what you want for Google Analytics.
public class Analytics : HelperPage
{
public static HelperResult GetPiwikHtml(Uri serverHost, int siteId)
{
string host = serverHost.Host;
return new HelperResult(x =>
{
HelperPage.WriteLiteralTo(x, " <!-- Piwik -->\r\n");
HelperPage.WriteLiteralTo(x, " <script type=\"text/javascript\">\r\n var pkBaseURL = ((\"https:\" == document.location.protocol) ? \"https://" + host + "/\" : \"http://" + host + "/\");\r\n document.write(unescape(\"%3Cscript src='\" + pkBaseURL + \"piwik.js' type='text/javascript'%3E%3C/script%3E\"));\r\n </script>\r\n");
HelperPage.WriteLiteralTo(x, " <script type=\"text/javascript\">\r\n try{\r\n var piwikTracker = Piwik.getTracker(pkBaseURL + \"piwik.php\", ");
HelperPage.WriteTo(x, siteId);
HelperPage.WriteLiteralTo(x, ");\r\n piwikTracker.trackPageView();\r\n piwikTracker.enableLinkTracking();\r\n } catch(err) {}\r\n </script>\r\n");
HelperPage.WriteLiteralTo(x, " <noscript><p><img src=\"http://" + host + "/piwik.php?idsite=" + siteId + "\" style=\"border:0\" alt=\"\" /></p></noscript>\r\n");
HelperPage.WriteLiteralTo(x, " <!-- End Piwik Tracking Code -->");
});
}
}
精彩评论