Use StatCounter to track visitor paths within your Flash site!

My company uses StatCounter to see what sections of our website people tend to visit, but now that we are switching to an all-Flash site, statistics only show the main page (since it is the one that holds the Flash movie). I decided to create a script that would track visitor paths within a Flash movie, and I figured I’d post it here in case anyone else needs something like it.


function sendClickData(clickVal, titleVal) {

    main_dir = "http://mysite.com/" //The directory where your flash movie is located.
    sc_project = "0000000"; //This should be your project ID, provided by StatCounter.
    sc_security = "00000000"; //Your security ID.

    if(!_global.referrer) {
        _global.referrer = main_dir;
    }
    //You may need to change this c21 to something else depending on the code StatCounter provides.
    sc_base_dir = "http://c21.statcounter.com/t.php?sc_project=" + sc_project;
    sc_url = main_dir + clickVal + ".html";
    sc_tracking_url = sc_base_dir;
    sc_tracking_url += "&resolution=" + scrWidth;
    sc_tracking_url += "&camefrom=" + _global.referrer + "&u="+sc_url;
    sc_tracking_url += "&t="+titleVal;
    sc_tracking_url += "&java=1&security=" + sc_security;
    
    sendVars = new LoadVars();
    sendVars.sendAndLoad(sc_tracking_url, sendVars, "POST");
    sendVars.onLoad = function(success){
        if(success){
            trace ("Data saved")
        }
    }
    _global.referrer = sc_url;
}

titleVal is what you want the title of your “page” to be. clickVal is the filename of your “page”, which could also include a subdirectory (“people/bob” would make the fake URL be “http://mysite.com/people/bob.html”).

If you are wondering where scrWidth comes from, I appended it to my JavaScript flash embed, with a value of screen.width (to find the user’s screen resolution with JS). If scrWidth is undefined, StatCounter simply won’t know what resolution the user has.

Enjoy! :slight_smile: