Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Javascript for Google Analytics

$
0
0

Hi All, 

I have implemented Multiview now i need to add Google Analytics for very view. I am trying to track every view user has viewed. from 1 to 5. 

Following is the code in <head> tags:

function GATools(){
var pname = pagename
var _gaq = _gaq || [];
_gaq.push(['_setAccount', pname]);
_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.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}

I'm calling above function from code behind when user is clicking Next button. 

code behind: 

Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs)

MVMaturityMatrix.ActiveViewIndex += 1
Dim vwId As String = MVMaturityMatrix.GetActiveView().ID

 If vwId = "View_1" Then

      Page.Title = "Step 1 - Order"

      StepNumber = 1

       GetGoogleAnalyticsEventTracking("/page1/introduction")

End If


If vwId = "View_2" Then

 StepNumber = 2

 Page.Title = "Step 2 - Receive"

  GetGoogleAnalyticsEventTracking("/page1/Receive")

End If

End Sub

Protected Function GetGoogleAnalyticsEventTracking(ByVal link_category As String) As String

     Response.Write("<script language='javascript'> GATools('" + link_category + "') </script>")

      Return String.Format("_gaq.push(['_trackPageview','{0}']);", link_category)

End Function

I am getting an error "JavaScript runtime error: 'GATools' is undefined"

Can you guys help me to sortout this problem. 

Thanks


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>