LogData Method (.NET)

 

The Enterprise Edition of BrowserHawk provides the ability to automatically gather statistics on your user’s browser capabilities and transmit them to the BrowserHawk Reports Web Service for storage in an Access or SQL Server database.

 

The BrowserHawk component communicates with the BrowserHawk Reports Web Service (BRWS) asynchronously so that there is no added delay or processing overhead incurred by your web scripts and web servers. This makes for extremely fast, efficient, and highly scalable stats collection and storage.

 

To communicate the results of a user's browser to the BRWS you call the static LogData method.

 

Syntax:

BrowserObj.LogData(BrowserObj bhObj, ExtendedBrowserObj extBrowObj);

BrowserObj.LogData(BrowserObj bhObj, ExtendedBrowserObj extBrowObj, string propertiesToLog);

BrowserObj.LogData(BrowserObj bhObj, ExtendedBrowserObj extBrowObj, propertiesToLog, string bhud);

BrowserObj.LogData(BrowserObj bhObj, ExtendedBrowserObj extBrowObj, string propertiesToLog, string bhud, string bhu2, string bhu3, string bhu4, string bhu5);

BrowserObj.LogData(BrowserObj bhObj, ExtendedBrowserObj extBrowObj, LogOptions logOptions);

bhObj: The instance of the BrowserObj class that contains basic property information for the stats being logged.

extBrowObj: The instance of the ExtenedBrowserObj class that contains extended property information for the stats being logged. If you are not logging any extended properties then you should pass in null for this parameter.

propertiesToLog: The names of the properties to be logged. If null, or if a method signature is used where the propertiesToLog is not included, the properties to be logged are obtained from your configuration in the BrowserHawk Editor.

bhud: Specifies a user-defined value to be stored in the userdata database column along with the statistics.

bhud2, bhud3, bhud4, bhud5: Specifies the user-defined value to be stored in the userdata2, userdata3, userdata4, and userdata5 database columns respectively along with statistics. This allows you to easily associate an important piece of information along with the statistics for the user. For example, you could pass in a user id or login name in these parameters. Then if the user reports a problem with your site to your support team, you can easily pull up their statistics and see exactly what their browser settings were at the time the error occurred. Note: userData1, userData2, and userData3 can be up to 255 characters in length each. Userdata4 and userData5 can be up to 50 characters in length each.

 

 

Note: Before using the LogData method you may want to set the list of properties you want this method to log by default. This can be done from BrowserHawk Editor->Special menu->Preference and Options->Reporting Options and Reports Database tabs by setting. Otherwise you can use the various method signatures shown above to pass in the list of properties to log.

 

Note: To record any of the extended properties you must call the GetExtendedBrowser method prior to calling the LogData method – otherwise BrowserHawk will log only the default values and not the browser's actual values.

 

IMPORANT TIP: You can use the BrowserHawk Editor to auto-generate the ASP, ASP.NET, ColdFusion MX, JSP, or servlet code needed to test the properties of interest and to call the LogData method to have the results inserted into your database. From the BrowserHawk Editor's main menu choose Special->Preferences and Options, then select the Reporting Options tab, and click on the Properties To Log button. Select the properties you are interested in logging in your database and press OK. Answer Yes when prompted if you'd like BrowserHawk to generate the scripting for you. The code in the example below was auto-generated by using this option.

 

Tip: The LogOptions class provides the most elegant approach for specifying various paramters. It is also the only means available for inserting a UserID or SessionID with the recorded data.

 

Example:

 

Assume you used the BrowserHawk Editor to configure BrowserHawk to log the user's browser type, version, Flash plug-in information, and whether ActiveX and Cookies are enabled. You then could use code such as this:

 

<%@ Page language="c#" %>

<%@ Import Namespace="cyScape.BrowserHawk" %>

 

<%

 

// Generated language: ASP.NET (C#)

 

// Note: Insert the following code block #1 at the top of your ASP.NET page, *before* the opening HTML tag.

// If you want to use this code from a CODE BEHIND page in VS.NET, this code block should be

// placed at the top of the Page_Load event (so that it is the first code to execute in that event). %>

 

<% // ------------------------ BEGIN CODE BLOCK #1 ------------------------ %>

 

<%

BrowserObj bhObj = BrowserObj.GetBrowser();

ExtendedOptions extOptions = new ExtendedOptions();

extOptions.AddProperties("ActiveXEnabled, CookiesEnabled, Plugin_Flash, Plugin_FlashVerEx");

 

extOptions.PageTitle = "Please wait...";

extOptions.PageMessage = "Please wait while your browser is checked..."; // This can be text or HTML

extOptions.BodyTag = "BGCOLOR=#FFFFFF";

ExtendedBrowserObj extBrow = BrowserObj.GetExtendedBrowser(extOptions);

// ------------------------ END CODE BLOCK #1 ------------------------

%>

 

<HTML><HEAD><TITLE>Your Page Title</TITLE></HEAD>

<BODY>

Your page content goes here ...

<%

 

// Put the following code block #2 just prior to your closing </BODY> tag for best results

// ------------------------ BEGIN CODE BLOCK #2 ------------------------

// Prevent logging stats multiple times for the same user

if (Request.Cookies["bhLogged"] == null) {

BrowserObj.LogData(bhObj, extBrow); // Note: This must be called somewhere between your <BODY> tags as shown here

Response.Cookies["bhLogged"].Value = "1";

}

// ------------------------ END CODE BLOCK #2 ------------------------

%>

</BODY></HTML>

 

Note: BrowserHawk Reports records a NULL value in the database for properties you did not configure it to track. For example, a value of 0 in the database for JavaScriptEnabled indicates the user had JavaScript disabled (1 indicates it was enabled). A value of NULL indicates that a value was not recorded because you did not request it to track this property.

 

See Also:

GetLogData Method

LogOptions class

About BrowserHawk Reports

Reporting Options

Reports Database