I've successfully added Analytics to an Android app and it is picking up session data just fine. However, I've also tried to track a specific event, but it does not seem to be sent to Analytics like the rest of the session data. I've followed the code suggested in the current Analytics documentation and still no luck, so I'm pasting here in the hopes that it's something obvious to more experienced folks. Many thanks in advance for any guidance.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_import);
user = getIntent().getStringExtra("user");
statusUpdateArea = (EditText)findViewById(R.id.dataStatusUpdateField);
progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.setVisibility(View.INVISIBLE);
welcomeMessage = (TextView)findViewById(R.id.WelcomeMessageTextView);
welcomeMessage.append(user);
// getting tracker & setting User ID field
AnalyticsApplication application = (AnalyticsApplication) getApplication();
mTracker = application.getDefaultTracker();
mTracker.set("&uid", user);
// build and send event
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("User ID")
.setAction("Data login")
.setLabel(user)
.build());
...
maybe you need use
mTracker = application.getTracker();
and
mTracker.setScreenName("yourscreenname");
Seems you are calling send before calling build .
Create a tracker with all the event info then call build and once done call send function .
Have worked on webtrends analytics product so I know a thing or two about analytics
Related
I am using firebase analytics in my app, and i track events like this:
public static String EVENT_MAIN_ACTIVITY_OPEN = "EVENT_MAIN_ACTIVITY_OPEN";
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Bundle bundle = new Bundle();
mFirebaseAnalytics.logEvent(EVENT_MAIN_ACTIVITY_OPEN, bundle);
These events are displayed normally in debug-view mode and in normal mode in firecase console.
Now, i want to block some events using GTM, without code fixes. How can i make this?
There are my variables, tags and triggers in GTM:
And I added GTM-xxxxx.json into main/assets/containers folder.
But event doesnt block (i track events view degub-view mode in firebase). So, how to resolve this?
I have a tough question. I looked around on the net, and while similar questions have been asked, this one hasn't. I'm currently building an Android app that uses Firebase and GTM.
I have the app setup correctly (I think). I added the appropriate lines to my gradle files, and when the app loads the debugger spits out the following:
I/FirebaseInitProvider: FirebaseApp initialization successful
It then says the following about GTM:
I/GoogleTagManager: Loading container GTM-XXX
I/GoogleTagManager: Installing Tag Manager event handler.
I/GoogleTagManager: Tag Manager event handler installed.
I/GoogleTagManager: Tag Manager initilization took 74ms
Thing is, I don't know how to track events, and the docs aren't very helpful. I have a event in GTM for 'session start' and that won't even fire. Furthermore, I tried the following code but it doesn't register in Firebase:
protected void onCreate(Bundle savedInstanceState) {
Log.d("asdf","Settings Activity create");
FirebaseAnalytics mFirebaseAnalytics;
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Log.d("asdf","Firebase object created");
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, "id");
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, "name");
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, bundle);
Log.d("asdf","Bundle sent");
// Bundle bundle = new Bundle();
// bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
// bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
// bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
// mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
super.onCreate(savedInstanceState);
setupActionBar();
}
My understanding of GTM is that I don't need to set it up on the device for it to run. My understanding is that you use the web browser app located here to setup all the tags, triggers, etc. The setup is then pushed onto your device and this allows you to turn events on/off at will. Its pretty handy, when it works.
What do I need to do to get GTM to work with my start session? What do I need to to do get Firebase to log events properly (one example here is more than enough)?
I can post the code for the project, but that seemed like overkill.
As per Google's questions:
The container has been published.
Firebase and GA analytics should be firing.
We get some feedback on firebase. It takes almost 24 hours for the events to show up though.
The GA info has never been published. See images below.
If you are using the Firebase+GTM SDK, you can setup in the GTM container session start trigger which is based on the automatically (out of the box) sent events from the Firebase+GTM SDK
Firebase should be automatically logging session start events. Can you try adding a trigger that matches event name "test", and then logging the following event via Firebase:
mFirebaseAnalytics.logEvent("test", new Bundle());
I made an application showing a window while calling in certain case, using service component.
The window contains info of callee.
I wanna know how to track this window.
Few buttons would be added with functions - ex : sending sms.
And I just wanna count how many times this window has been shown.
I found this question - Android: can I use Google Analytics inside a Service?
But it seems it's about old version of GA.
And I failed to make that in my app.
(I tried :
public class view extends Service {
...
GoogleAnalytics mGA;
Tracker gat;
...
#Override
public void onCreate() {
super.onCreate();
mGA = GoogleAnalytics.getInstance(app);
gat = mGA.getTracker("UA-my-account");
Map<String, String> params = new HashMap<String, String>();
params.put("event", "test");
gat.send(params); )
Let me know how to make tracker work in my app with GA V3.
Thanks for any help.
I made it.
GA = GoogleAnalytics.getInstance(YourContext);
Tracker = GA.getTracker("Your UA-xxxxxxxxxxxxxxxxxxx");
1. Tracker.send(MapBuilder.createEvent("category","action","label",long type value).build());
2. Tracker.set(Fields.SCREEN_NAME, "SCREEN NAME");
Tracker.send(MapBuilder.createAppView().build());
now wait for a day for this to be shown.
I'm having trouble while implemented the new google tag manager lib.
Here is what I did:
I create a macro dataleyr
I set a rule for an event
I create a tag and set the universal analytics ID on it
I publish my container
Then I tried to use it in my app like this
TagManager mTagManager = TagManager.getInstance(this);
DataLayer mDataLayer = com.google.android.gms.tagmanager.TagManager.getInstance(this).getDataLayer();
ContainerOpener.openContainer(
mTagManager, CONTAINER_ID, OpenType.PREFER_NON_DEFAULT,
TIMEOUT_FOR_CONTAINER_OPEN_MILLISECONDS, new ContainerOpener.Notifier() {
#Override
public void containerAvailable(Container container) {
container.refresh();
// Save container for use by any other activities in the app.
com.appsconceptelite.appsconceptelite.testfunctionnalities.gtm.ContainerHolder.setContainer(container);
mContainer = com.appsconceptelite.appsconceptelite.testfunctionnalities.gtm.ContainerHolder.getContainer();
Utils.pushOpenScreenEvent(LearnActivity.this, "Learn Screen");
}
});
and the method I use to push event is
/**
* Push an "openScreen" event with the given screen name. Tags that match that event will fire.
*/
public static void pushOpenScreenEvent(Context context, String screenName) {
DataLayer dataLayer = TagManager.getInstance(context).getDataLayer();
dataLayer.pushEvent("openScreen", DataLayer.mapOf("screenName", screenName));
}
When I run this code in debug mode, I get the right container name and version but when I check in Google Analytics dashbord, I see no events like if no data have been pushed.
Can you tell me what I'm doing wrong?
Not sure if it will solve the issue but what tripped me is the old google analytics account that hasn't been created a "Mobile apps" account and no results would be seen on the account but were definitely sent out. Create a new "Mobile apps" property and try again.
When using EasyTracker:
#Override
protected void onStart() {
super.onStart();
EasyTracker.getInstance().activityStart(this);
}
It work great, the problem that i am integrating from older version of analytics and i use it in a service and not in activity, so i cant use activityStart method.
I tried to use:
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(getApplicationContext());
final Tracker tracker = googleAnalytics.getTracker("UA-xxxxxx-y");
tracker.setStartSession(true);
tracker.sendView("/page");
And i dont see anything in the analytics (even after GAServiceManager.getInstance().dispatch())....
Is there any way to use new version of analytics whitout the activity???
Thanks
Found a way to not use EasyTracker.
It was actually in the oficial site:
https://developers.google.com/analytics/devguides/collection/android/v2/advanced
Basically this what you need to do:
At first initial the tracker like this:
// Get the GoogleAnalytics singleton.
mGaInstance = GoogleAnalytics.getInstance(this);
// Use the GoogleAnalytics singleton to get two Trackers with
// unique property IDs.
mGaTracker = mGaInstance.getTracker("UA-XXXX-Y");
Then you can get the tracker like this:
mGoogleAnalytics.getDefaultTracker();
And use it like:
mGoogleAnalytics.sendEvent(.....);
mGaTracker.sendView(....);
In a service you need to set the Context before sending a view
Try this:
EasyTracker.getInstance().setContext(this);
EasyTracker.getTracker().sendView("/page");