Integrate Google Analytics with Phonegap Application | Apache Cordova

Tracking user activities / behaviour is very important for business success. In Phonegap Application we’re going to use Google Analytics for tracking user activities . By using google-analytics-plugin we can track user activities, Clicks, Screens, Events, Transactions and more

Screen Shot 2015-07-10 at 6.50.55 pm

Steps for integrating google analytics:

Step 1: Login or Create Google Analytics Account

Step 2: Create New Property for Mobile App (not website) under your account

Step 3: Get your Google analytics ID (UA-XXXX-YYY)

Step 4: Create your phonegap project and add platform

Step 5: Add your plugin for integrate google analytics with phonegap

cordova plugin add https://github.com/danwilson/google-analytics-plugin.git

Step 6: Setup your google analytics tracking code on deviceready event
window.analytics.startTrackerWithId('UA-XXXX-YY')

To track a Screen (PageView):

  • window.analytics.trackView('Screen Title')

To track an Event:

  • window.analytics.trackEvent('Category', 'Action', 'Label', Value) Label and Value are optional, Value is numeric

To track an Exception:

  • window.analytics.trackException('Description', Fatal) where Fatal is boolean

To track User Timing (App Speed):

  • window.analytics.trackTiming('Category', IntervalInMilliseconds, 'Variable', 'Label') where IntervalInMilliseconds is numeric

To add a Transaction (Ecommerce)

  • window.analytics.addTransaction('ID', 'Affiliation', Revenue, Tax, Shipping, 'Currency Code') where Revenue, Tax, and Shipping are numeric

To add a Transaction Item (Ecommerce)

  • window.analytics.addTransactionItem('ID', 'Name', 'SKU', 'Category', Price, Quantity, 'Currency Code') where Price and Quantity are numeric

To add a Custom Dimension

  • window.analytics.addCustomDimension('Key', 'Value', success, error)

To set a UserId:

  • window.analytics.setUserId('my-user-id')

To enable verbose logging:

  • window.analytics.debugMode()

 

Share This

Share this post with your friends!