We help IT Professionals succeed at work.
Get Started

Google Analytics in asp.net

KaranGupta
KaranGupta asked
on
958 Views
Last Modified: 2013-11-08
Hi

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

So I referred this tutorial
http://www.aspcode.net/The-Google-Analytics-ASPNET-webcontrol.aspx

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
Regards
Karan      

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
            MyBase.OnInit(e)

        End Sub
        Private m_uacct As String = "UA-"
        <Bindable(True)> _
        <Category("Appearance")> _
        <DefaultValue("")> _
        <Localizable(True)> _
        Public Property uacct() As String
            Get
                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]

            Get

                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

                Return

            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>"

            output.Write(sScript)
        End Sub

    End Class

End Namespace

Open in new window

Comment
Watch Question
Commented:
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