Differences between Android and iOS when using Google Analytics in PhoneGap 1.2.0

青春壹個敷衍的年華 提交于 2019-12-10 03:54:27

问题


I've been trying to get Google Analytics to work in PhoneGap 1.2.0 over Android and iOS.

What are the main differences between Android and iOS when using Google Analytics in PhoneGap 1.2.0?


回答1:


The three main components required and the different parts for Android and iOS.

  1. GAP-alytics from phonegap-plugins

    • Android
      • GoogleAnalyticsTracker.java
      • analytics.js
    • iOS
      • GoogleAnalyticsPlugin.h / GoogleAnalyticsPlugin.m
      • GoogleAnalyticsPlugin.js
  2. Google Analytics from Google

    • Android
      • libGoogleAnalytics.jar (no source available)
    • iOS - these are included with the phonegap plugin for convenience
      • libGoogleAnalytics.a (no source available)
      • GANTracker.h
  3. PhoneGap from PhoneGap

    • Android
      • add <plugin name="GoogleAnalyticsTracker" value="com.package.path.to.class.GoogleAnalyticsTracker"/> to res/xml/plugins.xml file
    • iOS
      • In “Supporting Files/PhoneGap.plist” file add:
      • Plugins:
        • key = googleAnalytics (name used in the javascript) Value = GoogleAnalytics (name of Obj-C object)
      • External Hosts
        • ‘*’ (without quotes) as Item 0

NB: Remember that even though the iOS and Android versions have a phonegap-1.2.0.js file they are NOT the same file. The code is different and you can't just copy it between platforms. Make sure your app uses the appropriate version.


Android Javascript

window.plugins.googleAnalytics.start ("your UA code",       //UA-account ID
         function() { console.log("started") },             //successCallBack
         function() { console.log("didn't start") }         //failureCallBack
);



window.plugins.googleAnalytics.trackPageView (          //**NB**: NOTE CAPITAL 'V'
               "/Main Page",                                    //Page  (include /)
               function() {console.log("tracked page view")},           //successCallBack   
               function() {console.log("didn't track page view")}       //failureCallBack
);


window.plugins.googleAnalytics.trackEvent (
            "Contact",                                          //Category
            "Email",                                            //Action
            “John Smith”,                                       //Label
            0,                                                  //Value
            function() { console.log("tracked event") },        //successCallBack
            function() { console.log("didn't track event") }    //failureCallBack
);

iOS Javascript

window.plugins.googleAnalyticsPlugin.startTrackerWithAccountID(“your UA code”); 

window.plugins.googleAnalyticsPlugin.trackPageview(whichPage); //Note lowercase v in trackPageview.    

window.plugins.googleAnalyticsPlugin. googleAnalytics.trackEvent(
    "Contact",
    "Email",
    “John Smith”
    0, 
    function() { console.log("tracked event") },            //successCallBack
    function() { console.log("didn't track event") }        //failureCallBack
);

NB. the variable ‘whichpage’ MUST be preceded with a forwardslash (/). Android will let you away without this. iOS will NOT.



来源:https://stackoverflow.com/questions/8094604/differences-between-android-and-ios-when-using-google-analytics-in-phonegap-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!