views:

531

answers:

2

Hello,

Is there a way to track Google Analytics Events from Server Side in ASP.NET, the requirement is the the Event should be tracked on button click after some functionalities are executed on Serverside. ? OnClientClick of button, we cannot fulfill this requirement completely as some time serverside functionalities can fail but the event will get tracked in Google? Please help me in this regard.

Appreciate expert answers.

Thanks in Advance, Raj

A: 

In your server side code, you could use HttpWebRequest to send a request to a page that specificly sends data to Google analytics. This may slow down your page, so you could also try using the BeginGetResponse as well.

string url = "http://www.yoursite.com/SendPageView.aspx?action=buttonClick";
WebRequest webRequest = HttpWebRequest.Create(url);
webRequest.GetResponse(); //Also try BeginGetResponse()

In this case, the SendPageView.aspx page takes the action querystring and uses JavaScript to set a pageView to Google Analytics.

pageTracker._trackPageview("buttonClick");
James Lawruk
A: 

I tried this implementation, but since the web request does not execute javascript, it doesn't work.

/Thomas

tkahn