User Tracking/Reporting and maybe #url history as a bonus?

  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

Does anyone know of a stats software / tie in which specifically works well with Flash.

I like very much the functionality of unique hash urls for each page of your flash because it seem to be the most logical method for reporting URL activity to a user tracking software. But I havn't found much information (actionscript object classes or tutorials) which would help me get started.

Kris
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Hmmm Well you can actually tie into google analytics pretty well with Flash. The basic concept is that you call a javascript on the parent page at set points through out your flash movie.

For example I might call the js with an onRelease of a menu button to tell google that the page was loaded and so on.

I also hear that Mint (http://www.haveamint.com) will work with Flash but I haven't tried it personally.

As for adding the hash marks or fake directory structure to the url bar, thats completely different than general site tracking requirements. Instead its more for the user and if you plan to use things like deep linking in your flash project.

Here's a decent write up about deep linking. It might help with the concepts.

http://www.klynch.com/apps/flashlinking/howto.html

I should note that there are somewhat easier ways to interact with javascript from Flash than the ones they use in the example but the basic idea is there.
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

I was hoping on tying the two together, if I'm making a BrowserState it would generally be as a result of a new user action I want to track.

I suppose it is too much to ask for both. Your link was good though, I can change the function
Code: [ Select ]
function flashPutHref(href) { location.href = href; }

to

Code: [ Select ]
function flashPutHref(href) {
location.href = href;
urchinTracker(href);
}

//also I'd do the same to the VB subroutine
  1. function flashPutHref(href) {
  2. location.href = href;
  3. urchinTracker(href);
  4. }
  5. //also I'd do the same to the VB subroutine


However, I have a feeling that would track
page1.html#section=foo&page=bar
as being the same as
page1.html

Which leaves me with this flash example on Google Analytics.

But still that is not an example which a customer can copy and paste into a webrowser to see what page
/homepage/flashbuttons/button1 - Google's example
is actually referring to. (unless I work some mod-rewrite into the site, but I really don't want to do that)
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

I think they'll work together just fine. I was just saying that tracking an event with google wasn't Dependant on the change of the url and vice versa.

Your code with the urchinTracker would be my solution as well. Your correct except that as long as you change the href variable google will track that as a new event. Google will take anything you feed into that var and track it as a unique url. Basically you would get google tracking an event thats the same as the url (which isn't very pretty to read in google's reports but DOES work for deep linking).

However I worry that google would track URls differently if your also using them to pass server data. For example google would see
page1.html#MySection?type=dog and page1.html#MySection?type=cat as different pages even if they aren't and its just giving Flash some data.

If you can get away with out the FAST data in the URl however, and just use the page1.html#SectionName (which looks possible with that Flash class) All the tracking should work fine.

Your other option which might be a little cleaner is to call the urchinTracker update from within your flash movie at the same points where you call the setWindow function.

Code: [ Select ]
browserState.setWindowTitle("Kevin's Photo #"+String(photoIndex));
getURL("javascript:urchinTracker('/folder/file');");
  1. browserState.setWindowTitle("Kevin's Photo #"+String(photoIndex));
  2. getURL("javascript:urchinTracker('/folder/file');");


This way you get the best of both worlds. A unique url string for the user and a string in google thats a lot easier to read. The only catch I can see with this technique is that you have to actually remember to call the tracker every time you change a url which could get confusing if you have a big project.

I guess I should try your solution to see what I can get it to do. I have a customer who wants both the unique url and the tracking but I've been too busy to implement it.
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

I think you're right it should be done on the flash side, but maybe take it another level up, and build it into the class. Something like:
Code: [ Select ]

class UrchinBSM extends BrowserStateManager
{

    public function setValue(attribute:String, value:String)
    {
        this.currentState[attribute] = value;
        var newStr = stateToString(this.currentState);
        if (newStr != this.stateStr)
        {
            this.stateStr = newStr;
            
            // call out to script code on the containing web page to notify browser of new state
            if (this.isMSIE)
            {
                // Internet Explorer is more reliable with FSCommand from the ActiveX control to VBScript
                fscommand("putHREF", "#"+this.stateStr);
            }
            else
            {
                // Netscape, Mozilla, Firefox and others can use JavaScript directly
                getURL('javascript:flashPutHref("#'+this.stateStr+'");');
            }
            
            //****************I added
            //send to urchinTracking
            urchinStat(this.stateStr);
        }
    }
    
    private urchinStat function(urchinData){
        //****************I added
        //this.stateStr uses '&' signs instead of '/' but who knows what urchin won't take.
        getURL("javascript:urchinTracker("+urchinData+");");
    }
    
}
  1. class UrchinBSM extends BrowserStateManager
  2. {
  3.     public function setValue(attribute:String, value:String)
  4.     {
  5.         this.currentState[attribute] = value;
  6.         var newStr = stateToString(this.currentState);
  7.         if (newStr != this.stateStr)
  8.         {
  9.             this.stateStr = newStr;
  10.             
  11.             // call out to script code on the containing web page to notify browser of new state
  12.             if (this.isMSIE)
  13.             {
  14.                 // Internet Explorer is more reliable with FSCommand from the ActiveX control to VBScript
  15.                 fscommand("putHREF", "#"+this.stateStr);
  16.             }
  17.             else
  18.             {
  19.                 // Netscape, Mozilla, Firefox and others can use JavaScript directly
  20.                 getURL('javascript:flashPutHref("#'+this.stateStr+'");');
  21.             }
  22.             
  23.             //****************I added
  24.             //send to urchinTracking
  25.             urchinStat(this.stateStr);
  26.         }
  27.     }
  28.     
  29.     private urchinStat function(urchinData){
  30.         //****************I added
  31.         //this.stateStr uses '&' signs instead of '/' but who knows what urchin won't take.
  32.         getURL("javascript:urchinTracker("+urchinData+");");
  33.     }
  34.     
  35. }
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

You know its funny thats what I just ended up doing :-) I'm working on this right now so hopefully I'll have a working site this evening.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

flash.external.ExternalInterface
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

thats why i was asking about it :-)
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Ok I got mine about 90% working. Right now it sends a new url based on the section, changes the title and sends to urchin. I won't know if the tracking works for about 24 hrs but it seems like it should.

I couldn't get that class to function correctly with Flash 8 and a different javascript embed so I rewrote my own using Joebert's solution (flash.external.ExternalInterface)

Here's my actionscript

Code: [ Select ]
import flash.external.*;

function setBrowser(ID){
    trace("running set browser with ID of: "+ID);
    var pagetitle:String = "Site Title :: "+ID;
    var newURL:String = "#"+ID;
    ExternalInterface.call("flashPutHref", newURL);
    ExternalInterface.call("flashPutTitle", pagetitle);
    ExternalInterface.call("trackPage", ID);
}
  1. import flash.external.*;
  2. function setBrowser(ID){
  3.     trace("running set browser with ID of: "+ID);
  4.     var pagetitle:String = "Site Title :: "+ID;
  5.     var newURL:String = "#"+ID;
  6.     ExternalInterface.call("flashPutHref", newURL);
  7.     ExternalInterface.call("flashPutTitle", pagetitle);
  8.     ExternalInterface.call("trackPage", ID);
  9. }


and the javascript (I dumped the VBscript since the externalInterface is supposed to work with just about every browser)
Code: [ Select ]
<script language="JavaScript">
<!--
    function flashPutHref(href) {
        location.href = href;
        }
    function flashPutTitle(title) {
        document.title = title;
        }
    function trackPage(stat){
        var trackThis = location.href + "#" + stat;
        urchinTracker(trackThis);
        }    
-->
</script>
  1. <script language="JavaScript">
  2. <!--
  3.     function flashPutHref(href) {
  4.         location.href = href;
  5.         }
  6.     function flashPutTitle(title) {
  7.         document.title = title;
  8.         }
  9.     function trackPage(stat){
  10.         var trackThis = location.href + "#" + stat;
  11.         urchinTracker(trackThis);
  12.         }    
  13. -->
  14. </script>


The only think I don't have working is reading in the current url and setting the swf based on that. However, I think I can get that pretty quick.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Quote:
I won't know if the tracking works for about 24 hrs but it seems like it should.


Definately post back about that, I was considering working with the urchintracker like that awhile ago but fear of the unknown ultimately held me back.
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

Unfortunately I've got a bad suspicion that Google Analytics doesn't support the number sign in tracking.

About AJAX:
Quote:
# onethumb Says:
January 22nd, 2007 at 1:27 pm

@Niall:

Yes, except there’s a bug (or design?) in Google Analytics that drops everything after the hash, which nukes most AJAX apps tracking:

http://www.smugmug.com/gallery/123#456 becomes http://www.smugmug.com/gallery/123, and so does every other “page” in that gallery.

We’ve worked around it, but it’s nasty. We’d love to a real fix.



It looks like we're stuck with the recommendation of using the '/' seperator.

Hopefully I'm wrong.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Hmm... Nope the hashes break urchin's code. Infact it had a hard time with the AJAX used to draw the graphs. Fortunatly, because of the way I built mine its pretty easy to feed the correct thing to google and keep everything else the same.

I changed the javascript from:
Code: [ Select ]
function trackPage(stat){
   var trackThis = location.href + "#" + stat;
   urchinTracker(trackThis);
   }
  1. function trackPage(stat){
  2.    var trackThis = location.href + "#" + stat;
  3.    urchinTracker(trackThis);
  4.    }

to
Code: [ Select ]
function trackPage(stat){
   var trackThis = location.href + stat;
   urchinTracker(trackThis);
   }
  1. function trackPage(stat){
  2.    var trackThis = location.href + stat;
  3.    urchinTracker(trackThis);
  4.    }

The above code workes beautifly with urchin however this format returns the full url to google. If I only use the string and not the location.href the click in google shows up as "/string". Its sort of interesting that it requires the tag to look like a url with the '/' but it doesn't really kill things for my purposes.

Here's the working version (still doesn't read the url at run time. More a limitation of the way I built it the first time than the code) http://client.addsomespark.com/solos
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

So I've discovered another problem.

I'm trying to read the URL information back into Flash to set the initial state. I found out I can parse the url using javascript and get everything after the hash with window.location.hash which returns '#string'. This seems to work pretty well but IE 6 and less doesn't seem to like that script.

Any ideas? I suppose I could do this inside of Flash since document.location doesn't seem to have any problems in IE but it was nice to have access to the premade url functions in javascript.
  • krismeister
  • Graduate
  • Graduate
  • krismeister
  • Posts: 202

Post 3+ Months Ago

here you are
Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


<script>
fullLocation = String(document.location);
flashVarHash = fullLocation.substring(fullLocation.indexOf('#')+1);
if(flashVarHash == fullLocation){
    flashVarHash = "none";
}
document.write(flashVarHash);


</script>
<h1>Above here is my hash</h1>
</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Untitled Document</title>
  6. </head>
  7. <body>
  8. <script>
  9. fullLocation = String(document.location);
  10. flashVarHash = fullLocation.substring(fullLocation.indexOf('#')+1);
  11. if(flashVarHash == fullLocation){
  12.     flashVarHash = "none";
  13. }
  14. document.write(flashVarHash);
  15. </script>
  16. <h1>Above here is my hash</h1>
  17. </body>
  18. </html>
  • studioinlieu
  • Born
  • Born
  • studioinlieu
  • Posts: 3

Post 3+ Months Ago

graphic boy,

I'm looking to tie Analytics into my Flash site, but it's not a complete timeline.
My Flash site loads external .swfs on release of a movieclip.

Could you shed some light on how I could accomplish this, or point me into the direction of some resources? I've googled several, but they haven't ended up working quite right for some reason or another and I'm trying to nail this down.

Thanks so much.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Well things have changed quite a bit since this topic was originally written. Google now provides a Flash API that's intended to make the process of tracking pages even easier. Basically, you track an event not content in Flash. So in your button code you make the analytics call and pass in a text string. Google then shows the text string as a page instead of an actual page.

If you decide not to use the Google API you can always use the Flash External Interface to call the tracker javascript embedded in the page. In either case you still track a piece of text instead of an actual page.

Here's some info
  • studioinlieu
  • Born
  • Born
  • studioinlieu
  • Posts: 3

Post 3+ Months Ago

I thought the Google Flash API was only good for actionscript 3. I need to get it working in as2. Which method out there do you suggest I investigate further and try to implement? Thanks.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Well the absolute easiest way regardless of the version of AS your using is to simply call do a getURL pointed at some javascript as described http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55520here.

Code: [ Select ]
btnName.onRelease = function(){
getURL("javascript:pageTracker._trackPageview('/folder/file.html');");
}
  1. btnName.onRelease = function(){
  2. getURL("javascript:pageTracker._trackPageview('/folder/file.html');");
  3. }


A more elegant way is to use the Flash External Interface to call the same script. Example Here

Post Information

  • Total Posts in this topic: 18 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.