admin管理员组文章数量:1295861
I just signed up with google analytics and I am trying to find where to add the tracking code on my page. I know how insert in basic html pages, I just have inherited a site that is a .aspx
I just signed up with google analytics and I am trying to find where to add the tracking code on my page. I know how insert in basic html pages, I just have inherited a site that is a .aspx
Share edited Apr 23, 2012 at 9:13 McGarnagle 103k31 gold badges234 silver badges261 bronze badges asked Apr 23, 2012 at 7:26 user1350722user1350722 211 gold badge1 silver badge2 bronze badges4 Answers
Reset to default 4You can insert it anywhere and it would work, as long as it's not inside an ASP.NET control. A good place to put it would be inside your Master Page file, if you have one (that way you just add the code once for your whole site).
Many front-end developers remend putting your script at the bottom of the page, so that if it breaks, your page will still work. I think the Google Analytics code should be pretty solid though, so you could place it in your HTML head section.
Take the Asynchronous Tracking code (available in your Google Analystics pages) and place it just inside the <head></head>
element of your code:
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/css/screen.css" />
<link rel="shortcut icon" href="/images/favicon.ico">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics./ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
If you follow the link above, you'll see that you can split the script block, so that some of the code won't impact on the rendering of the page. However, you'll run the risk of losing some hits, if the user interacts with the page before the tracking code is loaded. So only do this if you have a specific need to do so.
GA Code of Google Analytics code is the Global Site Tag (gtag.js) tracking code for any property. Copy and paste the GA code as the first item into the of every webpage you want to track. If you already have a Global Site Tag on your page, simply add the config line from the snippet below to your existing Global Site Tag.
The Global Site Tag provides streamlined tagging across Google’s site measurement, conversion tracking, and remarketing products – giving you better control while making implementation easier. By using gtag.js, you will be able to benefit from the latest dynamic features and integrations as they bee available.
The tracking code is profile-specific, which is why you can only access it via the Profile Settings page for a specific profile. Please read Where can I find my tracking code? for full instructions.
本文标签: javascriptWhere Do I Place Google Analytics Code Inside ASPX PageStack Overflow
版权声明:本文标题:javascript - Where Do I Place Google Analytics Code Inside .ASPX Page? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741622749a2388905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论