Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Angulartics with Ionic Framework

I am trying to use Angulartics with Ionic Framework. However, nothing is tracking on google analytics. Here is how a set it up.

  1. index.html.slim file

    <script src="lib/angulartics/src/angulartics.js">
    <script src="lib/angulartics/src/angulartics-ga-cordova.js">
    

    javascript:

    (function(i,s,o,g,r,a,m)
      {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function()   {
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
        a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];
        a.async=1;
        a.src=g;
        m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', '#{ENV['GOOGLE_ANALYTICS_ID']', { 'cookieDomain': 'none' });` 
    
  2. Added it to my angular module

    angular.module('app', ['angularMoment', 'angulartics', 'angulartics.google.analytics.cordova', 'ngCordova'])`
    
  3. Adde $analyticsProvider to my config in routes

    .config ($analyticsProvider, $stateProvider, $urlRouterProvider) ->
    

I am not getting any data on my google analytics Dashboard. Can someone please explain how to install Angulartics in my ionic project.

like image 726
eNddy Avatar asked Mar 04 '15 23:03

eNddy


People also ask

Can Ionic be used for web development?

Ionic is a framework for developing hybrid applications that supports mobile and web platforms.

Is Ionic still used?

Yes, there are use cases for Ionic, if what you're looking for is a reactive web app - where your web code can be used to quickly produce a mobile version - but - going down that route, using a framework which has performance and availability issues hitting phone hardware means that you're effectively ignoring a lot of ...

Is Ionic front end or backend?

Think of Ionic as the front-end UI framework that handles all of the look and feel and UI interactions your app needs in order to be compelling. Kind of like “Bootstrap for Native,” but with support for a broad range of common native mobile components, slick animations, and beautiful design.

Which language is used in Ionic Framework?

Ionic apps are built using the languages of the web: HTML, CSS, and JavaScript. Thus, if you know how to build a basic web app, you already know how to build with Ionic. With Ionic, you can deploy a native iOS or Android app, native desktop app, or web app, all from a single, shared codebase.


1 Answers

Please take a look at the angulartics-ga-cordova script file here: https://github.com/luisfarzati/angulartics/blob/master/src/angulartics-ga-cordova.js

On line 48, it is expecting the GAPlugin.

var analytics = window.plugins && window.plugins.gaPlugin;

You will need to add this script to your main index file. https://github.com/phonegap-build/GAPlugin

Then you can add your google tracking info like this.

myApp.config ($analyticsProvider, googleAnalyticsCordovaProvider) ->
    $analyticsProvider.firstPageview(true)
    googleAnalyticsCordovaProvider.trackingId = GOOGLE_ANALYTICS_ID

Also, if you are using phonegap build, you will need to add the following line to your config.xml file.

<gap:plugin name="com.adobe.plugins.gaplugin" />
like image 113
Andy Kwong Avatar answered Oct 01 '22 08:10

Andy Kwong