QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Bitcoin BankingBuy, Sell, Store and Earn Interest
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Integrate Google Analytics in Intel XDK APP

Integrate Google Analytics in Intel XDK APP

database-design-analytics

This post is a part 47 of Intel XDK Complete Tutorial post series.

Google Analytics is the World’s best website analytics platform. You can also integrate Google Analytics in Intel XDK apps to find usage information of your app.

In this tutorial I will show you how to integrate Google Analytics in an Intel XDK app.

Cordova GAPlugin

You need to install third party GAPlugin plugin to send app usage information to Google Analytics account.

Screen Shot 2015-02-14 at 10.15.54 pm

Legacy Hybrid apps don’t support third party plugins therefore you cannot use this plugin in legacy hybrid apps.

Sending Usage Information

Here is the code you need to run to send basic usage information to Google Analytics account

<script type="text/javascript">
    document.addEventListener("deviceready", function(){
        /*
        Parameters:
        1. Success Callback
        2. Failure Callback
        3. Google Analytics Account ID to which information will be sent to. Ex: UA-12345678-1
        4. This plugins splits the data into chunks. This parameter represents seconds within which all the chunks will be send to the account
        */

        window.plugins.gaPlugin.init(function(){/* Success */}, function(e){ /* Failed */ }, "UA-XXXXXXXX-X", 10);
    }, false);
</script>

Tracking Pages

If you app consists of multiple pages then the above code will log visits in your GA account. But if you are using App Framework then your app is actually a single page app with multiple panels.

Panels behave like pages from user perspective. Therefore to track panel’s you need to call window.plugins.gaPlugin.trackPage on panel change.

Here is example code

window.plugins.gaPlugin.trackPage(function(){/* Success */}, function(e){ /* Failed */ }, "some.url.com");

Exiting App

While exiting app always call window.plugins.gaPlugin.exit function.

Here is example code

<body onunload='window.plugins.gaPlugin.exit(function(){/* Success */}, function(e){ /* Failed */ })'>
</body>

This finishes the pending tasks before exiting.

Tracking Events

Event Tracking is a method that you can use to record user interaction with website elements

Here is how to track events using this plugin.

/*
Parameters:
1)  resultHandler - a function that will be called on success
2)  errorHandler - a function that will be called on error.
3)  category - This is the type of event you are sending such as "Button", "Menu", etc.
4)  eventAction - This is the type of event you are sending such as "Click", "Select". etc.
5)  eventLabel - A label that describes the event such as Button title or Menu Item name.
6)  eventValue - An application defined integer value that can mean whatever you want it to mean.
*/

window.plugins.gaPlugin.trackEvent(function(){}, function(){}, "Button", "Click", "event only", 1);
Feb 14, 2015Narayan Prusty
JavaScript "..." OperatorJavaScript "class" Keyword
Comments: 2
  1. Guilherme
    5 years ago

    Hello, I tried to use this plugin but it not working. What I do, beacuse
    When the app starts, apprently it seems to have woret, but, when I check the the Analytics Report, it was not recorded no preview.

    Thank You!

    ReplyCancel
  2. Alexandr
    6 years ago

    Not working. I have added the code in every page of my app but dont get any data in google analytics.

    ReplyCancel

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

Narayan Prusty

I am a full-stack web developer. I specialize in Blockchain and JavaScript. This is my personal blog where I write about programming and technologies that I learn and feel interesting to share.

Image6 years ago 2 Comments Cordova
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
  • Cordova GAPlugin
  • Sending Usage Information
  • Tracking Pages
  • Exiting App
  • Tracking Events
Related Articles
  • Share Button for Intel XDK APP
  • Intel XDK Geolocation Tutorial
  • Push Notification in Intel XDK using Push Plugin
  • Track Adblock Users with Google Analytics
  • Push Notifications in Intel XDK using pushMobi
Our Sponsor
Freelance: I am available
@narayanprusty
Hi, I am a full-stack developer - focusing on JavaScript, WordPress, Blockchain, DevOps, Serverless and Cordova. You can outsource your app development to me.





Will get back to you soon!!!
WordPress
ReactJS
Meteor
Blockchain
Serverless
Kubernetes
DevOps
DB & Storage
Ejabberd
Let's get started
My Books

2014 - 2015 © QNimate
All tutorials MIT license