[AS3.0] GoogleAnalyticsと連携 (3)

そうだ! GoogleAnalyticsを学習しよう! :bouzu:
:check: 「Google アナリティクス | 公式ウェブサイト

AnalyticsLibrary (analytics.swc) を使ってみるよ。 :boy:

analytics_index
analytics_content1
[index]
[content1]

:caution: 要 Flash Player 9 以上
:caution: 要注意 サウンドが鳴ります。


Flash 向け Google Analytics トラッキング (v1.0.1.319) を使ってみる。 :boy:
:check: 「Adobe Flash 向け Google Analytics トラッキング - Google アナリティクス - Google Code

こちらに詳しい手順が書いてあるよ。 :bouzu:
参考資料「Adobe Flash の設定 - Google アナリティクス - Google Code
参考資料「Google Analytics Tracking for Adobe Flash 関連ドキュメントの日本語訳 : Media Technology Labs (MTL) : メディアテクノロジーラボ ブログ


ドキュメントクラスおよび主なクラスは、 :banana: [AS3.0] シーン遷移に挑戦! (6) 参照。

AddressManager.as (net.AddressManager.as)
package net {

  import flash.events.EventDispatcher;
  import flash.events.Event;
  import flash.display.DisplayObject;

  import com.google.analytics.GATracker;
  import com.google.analytics.AnalyticsTracker;

  import com.asual.SWFAddress;
  import com.asual.SWFAddressEvent;
  import events.CompoEvent;


  public class AddressManager extends EventDispatcher {
    // プロパティ
    private static var instance:AddressManager;
    private static var defaultTitle:String = "[AS3.0] シーン遷移に挑戦!";
    private var paths:Array;
    private var ids:Array;
    private var titles:Array;
    private static var basePath:String = "analytics33/";
    private var tracker:AnalyticsTracker;

    // コンストラクタ
    public function AddressManager() {
      init();
      setup();
    }

    // メソッド
    private function init():void {
      paths = new Array();
      paths[0] = "index";
      paths[1] = "content1";
      paths[2] = "content2";
      paths[3] = "content3";
      paths[4] = "content4";
      ids = new Array();
      ids["index"] = 0;
      ids["content1"] = 1;
      ids["content2"] = 2;
      ids["content3"] = 3;
      ids["content4"] = 4;
      titles = new Array();
      titles["index"] = "";
      titles["content1"] = "コンテンツ1";
      titles["content2"] = "コンテンツ2";
      titles["content3"] = "コンテンツ3";
      titles["content4"] = "コンテンツ4";
    }
    public function layout(target:DisplayObject):void {
      //デバッグモード
      tracker = new GATracker(target, "UA-******-*", "AS3", true);
      tracker = new GATracker(target, "UA-******-*", "AS3", false);
    }
    private function setup():void {
      SWFAddress.addEventListener(SWFAddressEvent.INIT, initialize, false, 0, true);
    }
    public static function getInstance():AddressManager {
      if (AddressManager.instance == null) {
        AddressManager.instance = new AddressManager();
      }
      return AddressManager.instance;
    }
    private function initialize(evt:SWFAddressEvent):void {
      SWFAddress.removeEventListener(SWFAddressEvent.INIT, initialize);
      var title:String = SWFAddress.getTitle();
      if (title != "") defaultTitle = title;
      SWFAddress.addEventListener(SWFAddressEvent.CHANGE, change, false, 0, true);
      SWFAddress.addEventListener(SWFAddressEvent.EXTERNAL_CHANGE, changeExternal, false, 0, true);

    }
    public function transit(id:uint):void {
      select(id);
      dispatchEvent(new CompoEvent(CompoEvent.SELECT, id));
    }
    private function select(id:uint):void {
      var path:String = paths[id];
      SWFAddress.setValue(path);
      track(path);
    }
    private function change(evt:SWFAddressEvent):void {
      var path:String = evt.pathNames[0];
      if (path == null) path = "";
      switch (path) {
        case "" :
        case "index" :
          SWFAddress.setTitle(defaultTitle);
          break;
        default :
          SWFAddress.setTitle(defaultTitle + " | "+ titles[path]);
          break;
      }
      SWFAddress.setValue(path);
    }
    private function changeExternal(evt:SWFAddressEvent):void {
      var path:String = evt.pathNames[0];
      var id:uint = ids[path];
      dispatchEvent(new CompoEvent(CompoEvent.SELECT, id));
    }
    private function track(path:String):void {
      if (path == null) path = "index";
       tracker.trackPageview(basePath + path);
    }

  }

}

HTML
<html>
<head>
<title></title>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="swfaddress.js"></script>

<script type="text/javascript">
  var flashvars = {};
  var params = {scale:’noScale’, salign:’lt’, menu:’false’, allowscriptaccess: ‘sameDomain’, allowfullscreen :’false’};
  var attributes = {id: ‘flashcontent’, name: ‘flashcontent’};

  swfobject.embedSWF("swfaddress.swf","flashcontent","500","400", "9.0.28","", flashvars, params, attributes);
</script>
</head>
<body>
<div id="flashcontent">
  <a href="http://www.adobe.com/go/getflashplayer">
  <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" />
  </a>
</div>
</body>
</html>

こんな感じに!

analytics33