I've incorporated the latest Google Services library into my app, and have added screen tracking using the code below:
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = analytics.newTracker(R.xml.global_tracker);
t.setScreenName(full_event);
t.send(new HitBuilders.AppViewBuilder().build());
My global tracker xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">false</bool>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">[redacted]</string>
where I've used the "all apps" property tracking code.
I send a screen name update manually each time a user visits a particular screen in the app.
The real time updates show fine in the Google Analytics web page, but for some reason the historical reporting is not working. I've looked online and there is a suggestion that it can take 48 hours to show when you first set it up. However I started sending analytics data on Monday and it's now Saturday and nothing is showing up.
Am I doing something wrong or should I just give it more time?
I don't have that many users of my app (a few hundred perhaps). Could it be that Google needs a certain volume of data before it shows any statistics?
Any thoughts gratefully received.
Andrew
I worked out what was wrong. My code above creates a new tracker every time a screen view is to be sent whereas you're only supposed to create one per instance of the app.
I also modified it so that it was sending back screen views based on each specific app (rather than the all apps code) as well as including code in my onStart and onStop methods to enable tracking of the app itself as well as exception handing etc.
All working now.
Related
I am adding Google Analytics tracking to my Unity game (opted in for GA instead of Firebase). I'm using GA v4, just downloaded this morning from Google, and Unity version 2018.3.14f1.
I've imported GAv4 package, have setup property ID (for Android, iOS and Others) in prefab, added prefab to hierarchy and I'm able to start session and send event using LogEvent method. These are visible in GA backoffice, I can see my device in real-time, device location and events it's firing.
However, problem is that it does not show LogScreen in the backoffice.
Here is the line that calls LogScreen:
googleAnalytics.LogScreen(new AppViewHitBuilder().SetScreenName("main_menu"));
This line is called after googleAnalytics.StartSession() so should be fine.
Just as a reference, here is my line to send GA event (which works and is visible in analytics console):
googleAnalytics.LogEvent(new EventHitBuilder().SetEventCategory("event_category").SetEventAction("event_action"));
I can't figure out what's the issue, as events are working fine, but LogScreen is not.
I would expect to see LogScreen shown in Active Page feed in GA real-time overview tab, but I can't see it, neither there nor anywhere else.
I have tested it on Android device only, Android 9, Xiaomi Mi8 Pro.
Also important notice: when running inside Unity IDE, it has no errors thrown but no data (even session and events) are not shown in GA console. Session and events ARE visible in GA console when running on mobile device.
Any directions on what am I doing wrong would be greatly appreciated!
I would use something else. GA is shutting down. Maybe you get the error because GA might restrict the access for the new comers. Your code seems okay.
https://www.semetis.com/en/resources/publications/google-will-shut-down-analytics-for-mobile-apps-in-2019
I have integrated Google Analytics into my Android app. The app is a photo printing app which contains a set of predefined themes that users can choose. However, is it possible to retrieve the stats from Google Analytics (e.g., the top 5 themes selected by user) using some api rather than using the Google Analytics console?
What you are looking for to retrieve the information is the Core Reporting API. Because the Google Analytics API requires all requests to be authenticated and your users are not authorized to access your Google Analytics account It is probably best to set up the API call on the server side using a service account here is an example of how to set up a python application to use a service account to access the API.
But what should your query be?
analytics.data().ga().get(
ids='ga:' + profile_id,
start_date='30daysAgo',
end_date='today',
metrics='ga:totalEvents',
dimensions='ga:eventLabels').execute()
Your application will need a way to access the results of the query from your own servers. You might also want to look into using the Google Analytics Super Proxy which solves a similar problem of allowing external users to access the results of an authenticated API request.
You could create an event in Google Analytics that would effectively track this. Events have Categories, Actions, labels, and event values. So you can fairly effectively add a theme or anything you wanted as a dynamic value. Then you would be able to search and sort in Google Analytics on the event category and find which Theme was used the most
#Override
public void themeSelected(String theme) {
// May return null if a Tracker has not yet been initialized with a
// property ID.
Tracker tracker = Tracker.getInstance(this);
// that are set and sent with the hit.
tracker.send(MapBuilder
.createEvent("Theme", // Event category (required)
"Theme Selected", // Event action (required)
theme, // Event label - Can dynamically set this with the theme that was selected so you can search in Google Analytics on it.
null) // Event value
.build()
);
}
Screenshot showing sorting off of the Event Label. My labels were numbers that users entered. Notice you can see the number of times each one was entered in the TotalEvents Column which should give you the information you were looking for
i would like to see the duration my users are in my app. I mean exitapp-startapp should be a measure in google analytics ?
When starting my app I call :
t.send(new HitBuilders.AppViewBuilder()
.setNewSession()
.build());
But how to indicate, that my app is stopped or exited ?
After some research on that topic I have come with the conclusion that an app does not explicitly report a session end. Rather the session duration is measured based on the time between the consecutive hits which have been reported since the beginning of a new session and either a session timeout or going to the background.
I am trying to send the custom data in google analytics version 4 where the sending procedure seems to be different then previous version, I have create a custom dimention from google analytics web page then with the corresponding index I am sending the repective value as mention below,
Tracker tracker = ((Application) getApplication())
.getTracker(TrackerName.APP_TRACKER);
tracker.send(new HitBuilders.AppViewBuilder()
.setCustomDimension(1, "info1")
.build());
tracker.send(new HitBuilders.AppViewBuilder()
.setCustomDimension(2, "info2")
.build());
from the logs it seems that the data is send but not sure as I am unable to view any data in the google analytics web page.
You'll have to create a custom report and select the custom dimension, and any metrics associated with that custom dimension. For some reason Google hasn't (and who knows if they will) update the Custom Variables report.
You can define a custom report (Google Analytics > Customization (top tab)), but you need to make sure you select the right Metric or your information will not appear (e.g. ga:hits). https://support.google.com/analytics/answer/1151300?hl=en
Alternatively you can query the information through Google Analytics Query Explorer, although not choosing the correct dimension / metric will result in no data to appear (e.g. ga:dimension1 + ga:hits). http://ga-dev-tools.appspot.com/explorer/
Obviously might take a few good seconds / couple of minutes for information to be available, and important for fresh information make sure the date range includes today (yes, it happens to best of us to refresh furiously and find out Google Analytics date range was up to yesterday :-)
Developer reference (for anyone else looking for it): https://developers.google.com/analytics/devguides/collection/android/v4/customdimsmets
I am trying to integrate Google Analytics on my Activities.
As per the google docs I read up on EasyTracker and added EasyTracker.jar to my libs and referenced the same, extended my Activities from "TrackedActivity" / "TrackedListActivity"
Also made an entry in the strings.xml file located under values
<string name="ga_api_key">UA-xxxxxxxx-x</string>
But whenever I log into Google Analytics I don't see any tracking displayed there.
Where have I gone wrong?
Add another string:
<bool name="ga_debug">true</bool>
And then check logcat to see any information from the Analytics library.
Google Analytic 1st time appear on website after about 24-48 hours. So if you are waiting for analytic after implementation then just wait for 48 hours.
did you give the following uses permission.
<uses-permission android:name="android.permission.INTERNET" />
GoogleAnalyticsTracker tracker = GoogleAnalyticsTracker.getInstance();
tracker.start("your analytics code", this.con);
tracker.setCustomVar(1, "Medium", "Mobile App");
tracker.trackPageView("ur activity name");
tracker.dispatch();
tracker.stop();