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 implementation not firing

See original GitHub issue

I’m trying to track app start (and other views) but nothing shows up on Google Analytics, and no errors are reported on the console

This is the code I’m using on app.component.ts

...
import { GoogleAnalytics } from '@ionic-native/google-analytics';
...
const GA_TRACKING_ID = 'UA-XXXXXXXXX-X';
const GA_TRACKING_DISPATCH = 3; // default 30, doesn't work either
...
export class MyApp implements OnInit {
  ...
  constructor(
    ...
    private ga: GoogleAnalytics,
  ) {}

  ngOnInit() {
    this.platform.ready().then(() => {
      console.log('platform ready');
      ...
      if (this.platform.is('cordova')) {
        console.log('platform is cordova');
        ...
        this.initGoogleAnalytics();
      }
    });
  }

  private initGoogleAnalytics() {
    console.log('registering tracker');

    this.ga
      .startTrackerWithId(GA_TRACKING_ID, GA_TRACKING_DISPATCH)
      .then(() => {
        console.log('Google analytics is ready now');
        
        // the component is ready and you can call any method here
        
        this.ga.debugMode(); // no debugging info shows up on console
        this.ga.setAllowIDFACollection(false); // either true or false doesn't work

        this.ga.trackView('start')
          .then(a => console.log('tracked start', a))
          .catch(e => console.log('tracking start failed', e))
        ;
      })
      .catch(e => console.log('Error starting GoogleAnalytics', e));
  }
}

The track start command should fire normally, with a dispatch of 3s, it should show up on analytics right away

Log result on console, no errors occured

platform ready
platform is cordova
registering tracker
Google analytics is ready now
tracked start Track Screen: start

For the record, Google Analytics Admin no longer allows registering mobile app tracking without firebase, so I created it as a website, and created a mobile view

I set the domain as https://mobile.website.com and tried setting the compaign url in trackView as https://mobile.website.com/start, and still nothing

I checked the tracking ID, and it’s correct

Info

ionic cli             : 4.5.0
ionic                 : 3.9.2
@ionic/app-scripts    : 3.2.1

cordova (Cordova CLI) : 8.0.0
Cordova Platforms     : android 7.1.3, browser 5.0.4

Android SDK Tools     : 26.1.1

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
selected-pixel-jamesoncommented, Dec 17, 2018

Ya that fixes it. But if you ever remove a platform using ionic cordova platform rm android`` and then re-add it using ionic cordova platform add androidit updates thepackage.jsonandconfig.xml files so that they are again using^1.8.6```. I’m not sure how to prevent that from happening.

3reactions
selected-pixel-jamesoncommented, Dec 15, 2018

Seems like this 1.8.6 issue has been going on for awhile. No response. No updates so it looks like our best bet is probably to just downgrade and make sure Ionic doesn’t automatically update it to 1.8.6. Rack another up one for Ionic Native. 👎

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ion-range's ion-input event does not fire - Ionic Forum
The root issue is caused by Ionic not having a way of synchronously updating the v-model ref. This results in a (hacky) workaround...
Read more >
ionViewWillEnter, ionViewDidEnter not firing - angular
I have a tabbed page on an Ionic app with the default page implementing the ionViewWillEnter method. It used to work fine but...
Read more >
Ionic 4 and the Lifecycle Hooks in Angular | by Paul Stelzer
In short: Whenever you wonder, why ngOnDestroy is not firing, just take a look at the DOM inspector and you will see that...
Read more >
Is Scroll Trigger working with Ionic 6? - GSAP
I've been trying to implement Gsap with ionic & angular and it seems like just don't work https://lampdigitalcol.web.app/666 ...
Read more >
The 9 Most Common Mistakes That Ionic Developers Make
Here are some reasons not to use the Folder-by-Type structure: The number of files in your folders can become vast; Finding all the...
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