Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically set ga_trackingId property?

I have a single app, but depending of user's choice, it will be monitored totally separated in google analytics, so I NEED to set "ga_trackingId" for EasyTracker programmatically.

I've tried EasyTracker.getTracker().setAppId(id) with no luck.

like image 231
Christian Avatar asked Dec 16 '25 23:12

Christian


2 Answers

The accepted answer didn't work for me, as I saw this in my logs:

`W/GAV3﹕ Thread[main,5,main]: Missing tracking id (&tid)`

The solution for analytics v3 is:

EasyTracker tracker = EasyTracker.getInstance(getContext());
tracker.set("&tid", "UA-XXXX-2");

Calling it this way got rid of the error and I can see my events on the analytics page.

like image 107
Dave B Avatar answered Dec 19 '25 11:12

Dave B


For changing the id for the EasyTracker, do this:

onStart()

EasyTracker.getInstance(this).set(Fields.TRACKING_ID, "<your_ga_id");
EasyTracker.getInstance(this).activityStart(this);

onStop()

EasyTracker.getInstance(this).activityStop(this);
like image 24
Ionut Negru Avatar answered Dec 19 '25 11:12

Ionut Negru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!