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

I am trying to get Google Analytics to work in PhoneGap 1.2.0 via Android and iOS.

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

+7
source share
1 answer

Three core components and different parts for Android and iOS are required.

  • GAP-alytics from phonegap-plugins

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

    • Android
      • libGoogleAnalytics.jar (no source)
    • iOS - they are included in the phonegap plugin for convenience
      • libGoogleAnalytics.a (no source)
      • GANTracker.h
  • Phonegap from Phonegap

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

NB: Remember that although the versions of iOS and Android have the phonegap-1.2.0.js , they are NOT the same file. The code is different and you cannot just copy it between platforms. Make sure your application is using 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 by forward-life (/). Android will get you out of this. iOS will not.

+12
source

All Articles