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());
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'm migrating from old google analytics to Firebase Analytics and now I'm tracking the screens using this:
mFirebaseAnalytics.setCurrentScreen(SectionManager.getInstance().getCurrentActivity(), name, null /* class override */);
And also tryed using this:
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "screen");
params.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, params);
And I'm tracking events using this:
Bundle params = new Bundle();
params.putString("category", "command");
params.putString("action", "test command");
params.putString("label", "command test label");
mFirebaseAnalytics.logEvent("ga_event", params);
I'm testing the application openning some screens and passing it's name, and also I'm pressing some times a button which executes the event tracking code I showed.
The first problem is that in firebase panel, I can't find the "test command" event... Don't sure where should I find it, but I can't find it.
The second problem is that I can see the "screen class" of the activities I'm using for opening the screens, which represents the name of the activity, but the name of the screens I passed as a parameter to firebase is not present. If i filter to show the screen name I got this:
User engagement Screen name Screen name % total Avg. time
(not set) NaN - 0m 0s -100
If you're using the setCurrentScreen() event, you should be able to see it at the Analytics > Events panel. Then, select screen_view and a screen with, beyond other stuff, a card titled firebase_screen will show you the sceen_view events grouped by the name you gave them when logging the event.
Another card titled User engagement will show you the screen_class you want to see, as well as the visualization percentage and average time spent on each screen.
Custom events (like your ga_event) should also be shown at the Analytics > Events section at the Firebase Dashboard.
Important: Custom events might take up to 24 hours after called to show up on Firebase.
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
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.
I'm having a situation with SyncAdapter I don't know how to fix.
I'm using periodic syncs. The onPerformSync method just logs some info for me to know that the process is working (no calls to notifyChanges in content providers or anything else).
The project consists of two apps: The first one creates a user account (for testing purposes only). The second holds the sync adapter. Note that this is perfectly legal for the scope of the project.
I first install the app with the account.
I can see the account has been created.
Then I install the app with the sync adapter and the first time it runs the synchronization hangs. Seeing the account sync settings, the spinner icon is continuously running and no log messages are registered (meaning it does not reach onPerformSync).
However, I can cancel the sync in the Settings and then the sync process starts working normally. This means the wiring between Account, Content Provider and SyncService is properly set.
I'm aware that adding/removing an account triggers other sync processes so I let a good lapse of time to go before installing the app with the sync adapter.
Any hints on why this is happening?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAccountManager = AccountManager.get(this);
// No worries here. The account exists and it's the one I want
Account[] accounts = mAccountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
// Just first account for TESTING purposes
if (accounts != null && accounts.length > 0)
account = accounts[0];
else {
Log.e(TAG, "No accounts set!!");
return;
}
// Set sync for this account.
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
ContentResolver.setIsSyncable(account, authority, 1); // Mandatory since 3.1
// Allows the provider to sync when internet connection is back
ContentResolver.setSyncAutomatically(account, authority, true);
// Add a periodic synchronization
ContentResolver.addPeriodicSync(account, authority, extras, POLL_FREQUENCY);
}
EDIT
I found out that calling cancel on the sync, makes it work. Not the best solution but it fixes the problem by now. I put this line combined with a "isFirstUse" flag.
ContentResolver.cancelSync(account, authority);