1

I'm stuck setting up google analytics in my ionic application. Main problem is that application won't work with error "Object(...) is not a function". Did someone get this error before?

I tried to reinstall the plugin and follow more than once the ionic and google documentations. I also tried to reinstall all the node modules. I was looking for the solution here and around internet but there is no posts yet (at least, the ones that I found).

@Injectable()
export class GAProvider {


    constructor(private ga: GoogleAnalytics) {
        this.ga.startTrackerWithId('xx-xxxxxxx-x')
         .then(() => {
           console.log('Google analytics is ready now');
        this.ga.trackView('test');
     // 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));

      }
}

this is my app.module.ts

@NgModule({
  declarations: [
   ....
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    HttpModule,
    StarRatingModule,
    IonicModule.forRoot(MyApp),
    AngularFireModule.initializeApp(firebaseConfig.fire),
    AngularFireDatabaseModule,
    Ionic2RatingModule,
    AngularFireStorageModule,
    GooglePlacesAutocompleteComponentModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ....
  ],
  providers: [
    ...
    GoogleAnalytics,
    GAProvider,
    ...
  ]
})

This is my error

Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at GoogleAnalytics.startTrackerWithId (http://localhost:8100/build/vendor.js:56910:152)
    at new GAProvider (http://localhost:8100/build/main.js:2000:17)
    at _createClass (http://localhost:8100/build/vendor.js:11307:20)

Thank you in advanced and hope it could be useful for someone else.

stefanodecillis
  • 160
  • 1
  • 1
  • 7
  • Is [this](https://stackoverflow.com/questions/54467262/getting-uncaught-in-promise-typeerror-object-is-not-a-function-error) what you are looking for? what is the version of ionic framework and ionic-native for GA you are using? – Suraj Rao Aug 12 '19 at 07:46
  • I looked up the other post. At first I thought it was that but instead I got the same error. I fixed GA version to 4.20 and I have ionic-framework 3.9.3 (ionic-angular type) – stefanodecillis Aug 12 '19 at 17:47
  • how are you importing? – Suraj Rao Aug 13 '19 at 07:54
  • I'm following the documentation at https://ionicframework.com/docs/native/google-analytics – stefanodecillis Aug 16 '19 at 16:13
  • use v3 docs for v3 framework. Here: https://ionicframework.com/docs/v3/native/google-analytics/ – Suraj Rao Aug 16 '19 at 16:15
  • Thank you. The documentation you gave me it works on a pure code layer. But my firebase and google analytics don't get any hit by the application, even the sdk approval. Hence i think that now the problem is somehow the configuration of the project itself on the console. Otherwise I wouldn't know, because the sdk is the one of firebase and the google analytics UA is the same but it doen't get any hit – stefanodecillis Aug 17 '19 at 11:09

0 Answers0