We help IT Professionals succeed at work.
Get Started

Google Analytics in asp.net

KaranGupta asked
Last Modified: 2013-11-08

I want to impement google analytics in my asp.net application.

So I referred this tutorial

Then I have created a custom control and add following code in it.(please see the code section)

Then I have referred the dll in my project and added the following code in my .aspx file

<%@ Register TagPrefix="analytics" TagName="GoogleAnalytics" Namespace="GoogleAnalyticsCtrl" Assembly="GoogleAnalyticsCtrl"%>

<analytics:GoogleAnalytics id="google1"  runat="server" uacct="UA-zzzzz-x"  DebugMode="false"></analytics:GoogleAnalytics>

But I am getting this error

1. The directive is missing a 'src' attribute.      
2.Unknown server tag 'analytics:GoogleAnalytics'.      

Is there anything wrong with the code.

Kindly advice

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace GoogleAnalyticsCtrl
    <DefaultProperty("uacct")> _
    <ToolboxData("<{0}:GoogleAnalytics runat=server></{0}:GoogleAnalytics>")> _
    Public Class GoogleAnalytics
        Inherits WebControl

        Protected Overrides Sub OnInit(ByVal e As EventArgs)
            Me.EnableViewState = False

        End Sub
        Private m_uacct As String = "UA-"
        <Bindable(True)> _
        <Category("Appearance")> _
        <DefaultValue("")> _
        <Localizable(True)> _
        Public Property uacct() As String
                Return m_uacct
            End Get

            Set(ByVal value As String)
                m_uacct = value

            End Set

        End Property

        Private m_DebugMode As [Boolean] = False

        <Bindable(True)> _
         <Category("Appearance")> _
         <DefaultValue("true")> _
         <Localizable(True)> _
         Public Property DebugMode() As [Boolean]


                Return m_DebugMode

            End Get

            Set(ByVal value As [Boolean])

                m_DebugMode = value

            End Set

        End Property

        Protected Overrides Sub RenderContents(ByVal output As HtmlTextWriter)

            If DebugMode Then


            End If

            Dim sScript As String = "<script src=""http://www.google-analytics.com/urchin.js"" type=""text/javascript"">" & vbCr & vbLf & "</script>" & vbCr & vbLf & "<script type=""text/javascript"">" & vbCr & vbLf & "_uacct = """ & uacct & """;" & vbCr & vbLf & "urchinTracker();" & vbCr & vbLf & "</script>"

        End Sub

    End Class

End Namespace

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE