Logo

Help with Web2stats



Please note that all functionanlity on this page will only work with a pro accoount.

Tracking custom data
Tracking Ajax and Flash interactions
Changing the default pause timer
Manually tagging links as downloads, outbounds, or clicks

Tracking custom data

Web2stats lets you track custom data on a per session basis for your visitors. The most common example of this is to automatically name each visitor to your site so that they are identified in your stats by more than just an IP address. You could also use it to track cookie values, ad campaigns, or anything you can think of.

You can track an unlimited number of key/value pairs per visitor session, although we ask that you keep it within reason (five or less). This is done via standard JSON (JavaScript Object Notation). Simply create an object called web2stats_custom_session and assign it your key/value pairs. Our javascript will automatically URL encode the values, so there is no need for you to do that yourself. This data will then be linked to this session within our database. Example code is shown below.

<script type="text/javascript">
  var web2stats_custom_session = { username: 'billy', shopping_cart_id: '293932-azjk' };
</script>

<!-- below is your hypothetical tracking code -->
<script src="http://www.web2stats.com/123.js" type="text/javascript"></script>


Your custom data will only be shown to you when you are viewing the details of a visitor session, and each value will have an icon next to it to easily distinguish your data from the standard data that we already track (Screenshot). The exception to this rule is for data identified as username (lower case, one word), which will be shown in place of a user's IP address when viewing your visitor log and action log.

Custom data will only be logged for a session the first time it is requested. It is too strenuous to check which data is old and which is new for every single action from a session. Therefore, it is advised not to create the web2stats_custom_session object until you have all the data you want to log. For example, on Web2stats, we are only logging user names and nothing else. We have our code (PHP) set up like the following example, so that web2stats_custom_session doesn't exist unless a user is logged in.

<?php
if( isset( $_SESSION['user']['username'] )) {
  echo 
"
  <script type='text/javascript'>
    var web2stats_custom_session = { username: '"
.$_SESSION['user']['username']."' };
  </script>\n"
;
}
?>


<!-- below is your hypothetical tracking code -->
<script src="http://www.web2stats.com/123.js" type="text/javascript"></script>


We are aware that not everyone has access to backend code (PHP or otherwise), for example all of you that are hosting your blog on typepad.com. There is still hope, however! When a visitor leaves a comment on most of these hosted blogs, the blog will save a few cookies that typically contain their name, email, and web site, so next time the visitor leaves a comment they don't have to fill out that data again. You can extract that data with local javascript and send it our way to automatically log this information about your visitors to Web2stats!

In the code below, swap out COOKIE for the name of the cookie you want to grab (leave the quotemarks!). Below the example code are the names of cookies for the most common blogging platforms. Simply replace COOKIE with the appropiate value.

<script type='text/javascript'>
function web2stats_get_cookie( name ) {
  var ca = document.cookie.split(';');
  for( var i in ca ) {
    if( ca[i].indexOf( name+'=' ) > -1 ) return decodeURIComponent( ca[i].split('=')[1] );
  }
  return '';
}
var web2stats_custom_session = { username: web2stats_get_cookie( 'COOKIE' ) };
</script>

<!-- below is your hypothetical tracking code -->
<script src="http://www.web2stats.com/123.js" type="text/javascript"></script>


Visitor name Visitor email Visitor web site
WordPress   comment_author_MD5HASH     comment_author_email_MD5HASH     comment_author_url_MD5HASH    
TypePad   typepadauthor     typepademail     typepadurl    

If you have suggestions for other blogs or services to add, please contact us. Note that support for blogger/blogspot is not available because your blog is hosted on the blogspot domain, but the cookies for comments are stored for blogger.com. For security reasons, our code isn't able to access cookies from other domains.

Note: WordPress adds an MD5 hash of your site URL to the end of your site's cookie names. Because this value is different for every site, you will have to add in this value manually. You can find out what your MD5 hash is by looking at the cookies that are on your computer for your web site. The MD5 hash will be the string of 32 random letters at the end of the cookie name. For example, comment_author_13ac739fe98ffa51bcca7193cbde0280 ... copy this string letter for letter. Good luck! :)

Note 2: This won't work on a blog hosted on wordpress.com, because they don't allow any JavaScript, hosted or local. Want that to change? Contact WordPress support asking to add Web2stats as one of their trusted providers. They already do this with YouTube and some other companies. If enough people request Web2stats, it might happen.

Note 3: You can track more than one cookie value. Just add on another value between the brackets, as is demonstrated here. Example:
var web2stats_custom_session = { username: web2stats_get_cookie( 'author_name' ), email: web2stats_get_cookie( 'author_email' ) };




Tracking Ajax and Flash interactions

Web2stats works great for tracking interactions with Javascript, Ajax, and Flash. You'll simply need to makes calls to our web2stats.log() function whenever you want to log a visitor action, with which you can specify a URL, title, and type.

For Ajax and/or Javascript, you'll want to use an "onclick" event handler for the link to call the log function. For example:
<a href="#menu" onclick="web2stats.log('#menu','Home'); return false;"><img src="media/menu/home.gif"></a>

Flash has a function called getURL() that you can call from within your Flash application at any time. You'll need to specify our function with the javascript: protocol. For example:
getURL("javascript:web2stats.log('#menu','Home');");

web2stats.log() takes 3 parameters as detailed below.

web2stats.log( href, title, type );

  • href: Required. The URL you want logged for this action. It doesn't have to be a real URL, you can just use it to describe the action or action category. If you do this we recommend starting the URL with a hash #, because they are clickable within our interface back to your site. If you just want to the log the URL as it is in the anchor tag, use the value this.href
  • title: Optional. The text you want to show up next to the URL. Our standard tracking code uses the text of the link itself but you may want to use something else.
  • type: Optional. The type of action you are logging. If left blank, it defaults to 'click'. Other options are 'download', 'outbound', and 'pageview'.

Examples

<a onclick="web2stats.log(this.href,'Front page demo click');"
   href="/demo">Check out the demo!</a>

<a onclick="web2stats.log('/downloads/sweet.mp3','Sweet MP3','download');"
   href="/mp3.php?file=sweet">Download</a>

<a onclick="web2stats.log(this.href,'Sweet MP3','download');"
   href="/mp3.php?file=sweet">Download</a>

<a onclick="web2stats.log('http://google.com','Google','outbound');"
   href="/redirect.php?url=google.com">Google.com!</a>


web2stats.log() by default creates a 500 millisecond second pause whenever it is called, to ensure the user's browser has time to talk to us before moving on to the next page. However, for tracking Ajax and Flash, this is completely unnecssary, as the URL typically doesn't change, other than perhaps a new #hash value. Details on changing this delay are in the next section.


Changing the default pause timer

Tracking visitor actions other than page views (downloads, outbounds, and clicks) adds a slight delay from the time a visitor clicks a link to when their browser reacts to that click. This delay is to ensure there is time for their browser to talk to our servers before it follows the link. This effect is undesirable, but also unavoidable if you want reliable tracking. It defaults to 500 milliseconds (half a second). You can change this to any value you want, but the shorter time you choose, the greater chance there is that we won't receive this data from the visitor.

To change the default time, create a JavaScript global variable called web2stats_pause_timer. It must go BEFORE your tracking code. If you wanted to change it to 200 milliseconds, for example:

<script type="text/javascript">
  var web2stats_pause_timer = 200;
</script>

<!-- below is your hypothetical tracking code -->
<script src="http://www.web2stats.com/123.js" type="text/javascript"></script>

To fully disable tracking for this data, you can do as follows:

Disable on SOME links

To disable tracking for any individual link, simply add the class web2stats_ignore to that link.

<a class="web2stats_ignore" href="http://sweetsite.com/cool.mp3">Sweet download</a>
<a class="existing_class web2stats_ignore" href="http://amazingsite.com">Amazing link</a>


Disable on ALL links

To disable downloads, outbound, and click tracking for ALL links, you must create a JavaScript global variable called web2stats_advanced_disable, and it must go BEFORE your tracking code. An example is shown below.

<script type="text/javascript">
  var web2stats_advanced_disable = 1;
</script>

<!-- below is your hypothetical tracking code -->
<script src="http://www.web2stats.com/123.js" type="text/javascript"></script>



Manually tagging a link as a download, outbound link or click


The following file extensions are automatically tagged as downloads by our tracking code:
7z, aac, avi, csv, doc, exe, flv, gif, gz, jpg, jpeg, mp3, mp4, mpeg, mpg, mov, pdf, phps, png, ppt, rar, sit, tar, torrent, txt, wma, wmv, xls, xml, zip

Likewise, links that start with the protocols listed below are automatically tagged as outbound links, supposing they don't point to the same domain that the code is currently running on:
http, https, mailto, ftp, telnet

You may wish to log downloads and outbounds on additional links that aren't supported by default by our code. Or, your site may have downloads and outbound links that link to an internal script first (typically to log the action in your own database) and then redirect the user to the actual file or link. These types of links do not get tagged automatically as downloads or outbounds, because they just look like internal links to the tracking code. There's no way for our code to know what will actually happen after the link is clicked.

Because of this, Web2stats has a feature that lets you force the tracking code to tag a link as a download, outbound link, or click (for Ajax/Flash/Javascript sites). Simply add one of the following classes to any link on your site, and our code will treat it as you have specified. The last class listed (web2stats_log) is for the 'click' type. Otherwise, use web2stats_log_download or web2stats_log_outbound if you want it to be marked like that.

<a class="web2stats_log_download" href="/mp3.php?file=sweet">Download this file!</a>
<a class="web2stats_log_outbound" href="/redirect.php?url=google.com">Check out Google!</a>
<a class="web2stats_log" href="javascript:MyAjaxFunction('HELLO!');">Click me!!</a>

These are logged similar to normal pages on your site with a URL and title. These are automatically extracted from the link by our tracking code. For the first example above, the title would be "Download this file!" and the URL would be "/mp3.php?file=sweet". If there is no text for the link, we try to grab something meaningful instead. For example, if it is an image, we'll grab the URL of the image and use that for the title instead.

If you wish to customize the URL and/or title for these, you'll need to use our web2stats.log() javascript function.


Back to top