question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ionic - Basic usage not working.

See original GitHub issue

First let me say I’m new to ionic so I may be doing something backwards or wrong.

I setup a simple project with the latest cordova and ionic. Placed the startTrackingWithId call in the MyApp constructor and a trackView call in the HomePage constructor (see below).

When running the app on my device the follow errors occur.

If this is not the right place to be posting this type of question/issue, my apologizes, please let me know where to post in the future.

2017-03-14 16:50:43.612543 analytics[2806:989870] ERROR: Unhandled Promise rejection: Tracker not started ; Zone: <root> ; Task: setTimeout ; Value: Tracker not started
2017-03-14 16:50:43.612702 analytics[2806:989870] ERROR: error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures.
2017-03-14 16:50:43.710839 analytics[2806:989870] Google analytics is ready now

ionic start --v2 analytics blank

Your system information:

Cordova CLI: 6.5.0 
Ionic Framework Version: 2.2.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.1 
ios-sim version: 5.0.13 
OS: OS X El Capitan
Node Version: v6.1.0
Xcode version: Xcode 8.2.1 Build version 8C1002

app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen, GoogleAnalytics } from 'ionic-native';

import { HomePage } from '../pages/home/home';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage = HomePage;

  constructor(platform: Platform) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      StatusBar.styleDefault();
      Splashscreen.hide();

      // Note: A real id was used during testing.
      GoogleAnalytics.startTrackerWithId('UA-XXXXXXXX-1')
        .then(() => {
          console.log('Google analytics is ready now');
          // Tracker is ready
          // You can now track pages or set additional information such as AppVersion or UserId
        })
        .catch(e => console.log('Error starting GoogleAnalytics', e));

    });
  }
}

home.ts

import { Component } from '@angular/core';
import { GoogleAnalytics } from 'ionic-native';
import { NavController, Platform } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public platform: Platform) {
    this.platform.ready().then(() => {
        GoogleAnalytics.trackView('page-home');
    });
  }

}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
victorsosacommented, Apr 25, 2017

instead of using the constructor like:

  constructor(public navCtrl: NavController, public platform: Platform) {
    this.platform.ready().then(() => {
        GoogleAnalytics.trackView('page-home');
    });
  }

use the ionViewDidEnter method like this:

ionViewDidEnter() {
  GoogleAnalytics.trackView('page-home');
}

that will fix the issue

0reactions
victorsosacommented, May 3, 2017

Check the readme file for more doc updates

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component not working - Ionic Forum
I'm having trouble getting a basic component to work. ... You can use that module file for fast import(just import module in app.module.ts...
Read more >
Ionic 4 basic ngClass not working as expected [duplicate]
Posting a solution if anyone ever stumbles across this: Basically I was trying to change the variable outside of the "angular zone" after ......
Read more >
The 9 Most Common Mistakes That Ionic Developers Make
Common Mistake #9: Prototyping Ionic Applications Manually​​ They are actually rather minimal and have a good aesthetic. Presenting wireframes and mockups with  ......
Read more >
10 Common Ionic Problems & Error Messages (And How to ...
10 Common Ionic Problems & Error Messages (And How to Fix Them) Last update: 2018-01-16 · 1. Cannot read property 'xyz' of undefined...
Read more >
Ionicons Usage Guide
Usage. Ionicons is a completely open-source icon set with 1,300 icons crafted for web, iOS, Android, and desktop apps. Ionicons was made for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found