Using the CountryStats Object

The CountryStats object is used to obtain the total number of hits that have been encountered for each country since the CountryHawk component was loaded into memory. Each time CountryHawk processes a look up for a particular country, it automatically increments the internal hit count for the matching country by 1.

ActiveX/COM: You create an instance of the CountryStats object by specifying the class ID string of "cyScape.CountryStats" in your call to CreateObject. Once you have this object, you can request stats for a particular country, or stats for all countries using "FOR EACH / NEXT" syntax. You can also request the total hits for a particular country using the CountryStats object.

Native .NET: You create an instance of the CountryStats object by declaring a variable of type CountryStats and setting it to "new CountryStats()". Once you have this object, you can request stats for each country using enumeration with the "foreach" statement. To request total hits for a particular country, use the CountryObj HitCount property. This is demonstrated in the ch_statsByCountry ASP.NET sample.

Tip: By default CountryHawk keeps the statistics in memory only, so the statistics are cleared each time you restart your web services or applications that use CountryHawk. However, you can use the PersistToFile and LoadFromFile methods of the CountryStats object to persist the statistics and keep running totals on an ongoing basis!

See the CountryStats Object Properties and Methods for details on all properties and methods supported by this object.

ActiveX/COM examples:

Example - Obtaining total hits for a particular country:

set statsObj = CreateObject("cyScape.CountryStats")

response.write "Total hits for US are: " & statsObj.Total "US"

Example - Obtaining total hits for all countries - most to least hits (ActiveX/COM):

set statsObj = CreateObject("cyScape.CountryStats")

foreach country in statsObj

response.write country & ": " & statsObj.Total(country) & "<br>"

next

Tip: Total is the default property for the CountryStats object. Therefore you can use statsObj(country) instead of statsObj.Total(country) if you prefer.

.NET examples:

Example - Obtaining total hits for a particular country (VB.NET):

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

CountryObj chObj = CountryObj.GetCountry("US")

Response.Write("Total hits for US are: " + chObj.HitCount)

Example - Obtaining total hits for a particular country (C#):

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

CountryObj chObj = CountryObj.GetCountry("US");

Response.Write("Total hits for US are: " + chObj.HitCount);

Example - Obtaining total hits for all countries - most to least hits (C#):

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

CountryStats ctyStats = new CountryStats();

foreach (CountryObj chObj in ctyStats)

{

 Response.Write(chObj.CountryCode + ": " + chObj.HitCount);

}

Tip: The .NET version of CountryHawk supports ordering the stats by hits from least to most, by country name, or by country code. See the ch_statsByCountry_vb.aspx sample for more information.

Note: Use of the CountryHawk statistics feature and related properties and methods requires the Enterprise Edition of CountryHawk.

See Also:

Using the RegionStats Object

Collecting Stats in Real-time

Collecting Stats by Batch Processing Log Files

Persisting Statistics

CountryStats Object and Methods

RegionStats Object and Methods