Integration of angulars with ionic structure

I am trying to use Angulartics with the Ionic Framework. However, Google Analytics does not track anything. This is how it is configured.

  • 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' });` 
  • Added it to my angular module

     angular.module('app', ['angularMoment', 'angulartics', 'angulartics.google.analytics.cordova', 'ngCordova'])` 
  • Adde $ analyticsProvider for my route configuration

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

I do not receive any data on my Google Analytics toolbar. Can someone explain how to install Angulartics in my ion project.

+6
source share
1 answer

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

Line 48 expects GAPlugin.

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

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

You can then add your Google tracking information like this.

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

In addition, if you are using the phonegap assembly, you need to add the following line to the config.xml file.

 <gap:plugin name="com.adobe.plugins.gaplugin" /> 
+4
source

Source: https://habr.com/ru/post/983346/


All Articles