Code execute once on start


#1

My questions is if there is a way in Ionic 2 to execute code only once for example the google analytics init

this.ga.startTrackerWithId('YOUR_TRACKER_ID')
   .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));

Where should i put it?. Thanks


#2

I would put it in the constructor of the app component.