Sitata / titanium-google-analytics

Google analytics for Appcelerator Titanium
MIT License
92 stars 47 forks source link

Analytics working only for first window in iOS #23

Closed hardikamal closed 9 years ago

hardikamal commented 9 years ago

I have about 8 windows where i have written the below code...but this code only works when on home screen.I have been receiving this error when navigating to another screen in iOS 2015-03-16 20:10:11.214 MyApp[99143:395400] -[__NSCFString set:value:]: unrecognized selector sent to instance 0x7f8eda4553d0... If i remove this code the app works fine...

var GA = require('analytics.google'); //GA.optOut = true; GA.debug = true; //GA.trackUncaughtExceptions = true;var GA = require('analytics.google');

GA.trackUncaughtExceptions = true; // ios only // if you wanted to disable analytics across the entire app, you would set optOut to true GA.optOut = false; // set dryRun to true if you are debugging and don't want to capture data (default is true) GA.dryRun = false; // Data collected using the Google Analytics SDK for Android is stored locally before being // dispatched on a separate thread to Google Analytics. // By default, data is dispatched from the Google Analytics SDK for Android every 30 minutes. GA.dispatchInterval = 15; // minutes

var tracker = GA.getTracker(Alloy.CFG.trackingId); var tracker = GA.getTracker("UA-XXXXXXXX-2"); Ti.API.info("trackerid = "+Alloy.CFG.trackingId); tracker.trackScreen({ screenName : "ListScreen" });

Please Help...Thanks

astjohn commented 9 years ago

@hardikamal,

Try moving just the setup of the module to your alloy.js file. i.e. all the GA.whatever methods. Then on each screen, you will only have:

var GA = require('analytics.google');
var tracker = GA.getTracker(Alloy.CFG.trackingId);
tracker.trackScreen({
  screenName : "ListScreen"
});

Please let me know if that solves the issue or not.

hardikamal commented 9 years ago

Alloy.js Alloy.Globals.GA = require('analytics.google');

if(OS_IOS){ Alloy.Globals.GA.trackUncaughtExceptions = true; // ios only }

// if you wanted to disable analytics across the entire app, you would set optOut to true Alloy.Globals.GA.optOut = false; // set dryRun to true if you are debugging and don't want to capture data (default is true) Alloy.Globals.GA.dryRun = false; // Data collected using the Google Analytics SDK for Android is stored locally before being // dispatched on a separate thread to Google Analytics. // By default, data is dispatched from the Google Analytics SDK for Android every 30 minutes. Alloy.Globals.GA.dispatchInterval = 15; // minutes

Ti.API.info("USING TRACKING ID: " + Alloy.CFG.trackingId);

i have done this but this also doesnot seems to work

var tracker = Alloy.Globals.GA.getTracker(Alloy.CFG.trackingId); tracker.trackScreen({ screenName : "ListScreen" });

mattberg commented 9 years ago

Hi astjohn -

So just to clarify, calling:

var tracker = GA.getTracker(Alloy.CFG.trackingId);

on subsequent Windows/Views will use the same "instance" that is created in app.js?

Really appreciate your work on this module. Looking forward to implementing this evening.

Thanks, Matt

astjohn commented 9 years ago

@mattberg, I'd have to double check if the module is a true singleton or not, but in our app, we create an instance of the tracker returned from getTracker on Alloy.Globals for convenience within app.js.

soumyakantikar commented 9 years ago

Yes. In most of the apps I have seen that we generally create an instance of the module and keep it in Alloy.Globals variable.

On Tuesday, March 17, 2015, Adam St. John notifications@github.com wrote:

@mattberg https://github.com/mattberg, I'd have to double check if the module is a true singleton or not, but in our app, we create an instance on Alloy.Globals for convenience within app.js.

— Reply to this email directly or view it on GitHub https://github.com/Sitata/titanium-google-analytics/issues/23#issuecomment-82664380 .

hardikamal commented 9 years ago

@astjohn can you please create a sample with multiple screen(window)...that would be great...

@soumyakantikar even i did that but getting crashed when moved to second window... If you have any sample that is working with multiple windows can u please share it?

astjohn commented 9 years ago

@hardikamal

// Alloy.js

var GA = require("analytics.google");
Alloy.Globals.tracker = GA.getTracker(Alloy.CFG.googleAnalyticsId);
// Controller_A.js

Alloy.Globals.tracker.trackScreen({
  screenName: "This is controller A"
});
// Controller_B.js

Alloy.Globals.tracker.trackScreen({
  screenName: "This is controller B"
});

Create a fresh, brand new app with this code. That's all it should take. If it doesn't work, please share the fresh, brand new app with the above code on github and I'll take a look.

hardikamal commented 9 years ago

Awesome its working Thanks bro :+1:

mattberg commented 9 years ago

@astjohn thanks, I think the official GA SDK says it is a shared instance, but I wasn't sure how that translated to the Titanium implementation. The app (J23) that I am implementing this on is using the classic commonjs style, not alloy.