phonegap与google analytics整合

用phonegap开发的app接近尾声,需要整一个谷歌分析进去。

1.首先申请一个GA帐号,在“what would you like to track”下选择APP

 

2.整合phonegap下的GA plugin

github:https://github.com/DoersGuild/Cordova-Android-Analytics

这里需要注意的是在res文件夹走下去是一份XML,里面可以配置GA帐号。

整合步骤详细可以查看github的readme。这里简要复述下:

  •   在index.html中加载analytics.js
  •      将jar文件复制到项目的libs下,并且右键"build path"-"add to build path"
  •      打开项目的文件夹找到src,将下载内容中的src中的东西复制进去
  •      将下载内容的res中的XML文件复制到项目的res/values下并修改其中的GA账号
  •      打开AndroidManifest.xml,在<application>标签下加入
        <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name">
          <intent-filter>
          </intent-filter>
        </activity>
  •      在res/xml/config.xml下写入<plugin name="GoogleAnalyticsTracker" value="com.phonegap.plugins.analytics.GoogleAnalyticsTracker" />
  •      木有了~~~

 

3.写上需要track的内容示例:

window.plugins.analytics.start(function(){
            Track.bind();
            window.plugins.analytics.trackPageView('start',    function(){}, function(){});
            console.log('ga ok');
        }, function(){
            console.log('ga fail');
        });

具体的API用法可以参照github的readme以及自己查看analytics.js中的代码:)

 

4.查看结果

如果一切顺利,在你的GA账号下选择Real-Time - Overview 就能看见结果了

 

希望对你能有帮助。

 

posted @ 2013-07-25 11:06  ajccom  阅读(335)  评论(0编辑  收藏  举报