Posted By

chrisaiv on 02/03/09


Tagged

environment as3 capabilities runtime


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


As3: Track Pageviews only in Production Mode


 / Published in: ActionScript 3
 

There are many ways to tweak this code but hopefully this will get you all started. Whenever I'm tracking PageViews or Events for something like Google Analytics, I don't want navigateToURL() to interfere while I'm developing. These two functions will keep navigateToURL() from trying to load a Browser page until the SWF is loaded into an HTML page

  1. var mc:MovieClip = new MovieClip();
  2. mc.buttonMode = true;
  3. mc.addEventListener( MouseEvent.CLICK, trackEventHandler, false, 0, true );
  4.  
  5. function isProductionMode():Boolean
  6. {
  7. var runtimeEvironment:String = Capabilities.playerType;
  8.  
  9. if (runtimeEvironment == "External" || runtimeEvironment == "StandAlone"){
  10. return false;
  11. } else {
  12. return true;
  13. }
  14. }
  15.  
  16. function trackEventHandler( e:Event ):void
  17. {
  18. //If the Complied Flash Player is on the HTML page, give it a Page View
  19. if( isProductionMode() ){
  20. navigateToURL(new URLRequest("analytics._trackPageView()"), '_self');
  21. }
  22. }

Report this snippet  

You need to login to post a comment.