user6698813 user6698813 - 1 year ago 107
ASP.NET (C#) Question

Google analytics Code doesn't work for webfom using master

where do i add my Google analytics tracking code in my asp website having Webform with master page.
when i add it to master page before

Tag , It only tracks the content of Master page.
But it want to track my Webform formed using Master page, what should i do??.

Answer Source

Add it on end of master page (before closing body tag) like this:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!DOCTYPE html>

<head runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">


    <%--Google analytics and others javascripts api and plugin must be here--%>
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        ga('create', 'UA-XXXXXXXX-1', 'auto');
        ga('send', 'pageview');    

Any page that used this master page will tracked by analytics (GA). 48 hour after creating your property in GA you can track users real time in GA console.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download