Skip to main content

Google Analytic Helper Class ..



Google analytic is very powerful and handy utility provided by the Google to track your web site traffic from all over the word.

To use this Google analytic with our asp.net page we have to put one java script code into the page based on the WebPropertyId of the analytic profile from which we track our site.

Following are the some ready made methods of helper class which help you to play with google analytic into your asp.net page

Please download following assembly to use the helper class methods


1) getTrackerCode

GADCAPI.GADCAPIHelper.getTrackerCode(string WebPrppertyId)

This method return the java script which used to place into the page to activate google analytic tracker on that particular page.

Output:

var gaJsHost = ((""https:"" == document.location.protocol) ? ""https://ssl."" : ""http://www."");
document.write(unescape(""%3Cscript src='"" + gaJsHost + ""google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E""));

try {
var pageTracker = _gat._getTracker(""U-XXXXXXXX-X"");
pageTracker._trackPageview();
} catch(err) {}

(script tags are omitted because of post rendering made them activate)

2)  getProfilesList

public static List getProfilesList(string EmailAddress, string Password)

This method get your analytic account user name and password and return generic List of Class ProfileInfo.

ProfileInfo is class which have following properties

1) Url - profile url
2) WebPropertyId - U-XXXXXXXX-X like unique code for profile given by the 
analytic
3) ProfileId - this is profile id which is used to get profile data into the Google Analytic Dashboard Controls

Output:

URLWebPropertyIdProfileId
jigneshsuvariya.blogspot.com/UA-11462261-123177177



To find more utility control please refer the post Google Analytic Dashboard Controls into the category web control


Popular posts from this blog

Message Panel

This in post show you how effectively you can show you messages and error regarding the user events using the Message Panel control. following are the step by step description of how to create and use Message panel. Create Message panel In your application add folder App_Code. To do that right clicking on Web project select Add Asp.net folder >> App_Code Add one class file name MessagePanel.cs and copy pest following code into it. using System; using System.Web.UI; using System.Web.UI.WebControls; namespace Controls {    // TODO: add clear link (display: none;) plus requried js    [ ToolboxData ( "<{0}:MessagePanel runat=\"server">" )]     public class MessagePanel : Panel , INamingContainer     {         private const string VSKEY_MESSAGE = "Message" ;         private const string VSKEY_ERROR = "Error" ;      ...

LINQ union with group by

In my recent development activity with LINQ query, I need to get the some of user points from tow different tables where user's points are based on some activities. There are many users who are into one table but not in another table and some are in both table. For example tables having data like this Table 1 UserID   Points 1           10 2           20 Table 2 UserID    Points 2           20 3           30 Result should be UserID    Points 1           10 2           40 3           30 I try to get this result with LINQ query using joins and group by samples from the web. I had googling to get something useful but dont get any success. So I try with new logic and here it is, I think it will help full to other also. Example Item class to use public cla...

SqlConnection from ObjectContext.Connection

Following is C# code to get the  SqlConnection from ObjectContext.Connection . This is usefully to run dynamically created query using ADO.NET using connection string specified into the EDMX ObjectContext object. C# Code Example : using ( EntityContext context = new EntityContext ()) { EntityConnection ec = ( EntityConnection )context.Connection; SqlConnection sc = ( SqlConnection )ec.StoreConnection; SqlDataAdapter da = new SqlDataAdapter (strQuery, sc); DataSet ds = new DataSet (); da.Fill(ds); return ds.Tables[0]; }