Android Campaign Measurement Not Working - android

Ok, I have been all over looking for an answer as to why my Google Play campaign measurement is not working. I am not getting any data in my Analytics account. Here is what I have:
Google Play Services version 6171000 imported into my project and added as a reference.
Google Play App version 5.0.38 on my testing device
In my res\xml\global_tracker.xml file I have:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="https://schemas.android.com/tools" tools:ignore="TypographyDashes">
<integer name="ga_sessionTimeout">300</integer>
<string name="ga_trackingId">MY-TRACKING-ID</string>
<bool name="ga_debug">true</bool>
<!-- Enable automatic activity tracking -->
<bool name="ga_autoActivityTracking">false</bool>
<!-- Enable automatic exception tracking -->
<bool name="ga_reportUncaughtExceptions">true</bool>
</resources>
In my Manifest I have:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
and within <application> I have:
<!-- Used for Google Play Store Campaign Measurement -->
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver
android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="#xml/global_tracker" />
Now, I did the getTracker method in my extended Application class suggested by the Analytics setup document, but I don't think that is needed for just the app download tracking. Please correct me if I'm wrong here and I will post the code I have for that as well.
To test I have tried running
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.my.package/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
and I get a "Broadcast completed: result=0"
and then open my app on my device and I get nothing in the logs about campaign. Although I did read that this is not the proper way to test when using V4.
I've also packaged my app and uploaded to the Beta section of my store listing. While logged into one of my beta tester accounts, I opened the following in my browser and downloaded the app.
https://play.google.com/store/apps/details?id=com.my.package&referrer=utm_source%3DTestSite%26utm_medium%3DsideBanner%26utm_term%3DTestTerm%26utm_content%3DTestContent%26utm_campaign%3DtestCampaign
This I would expect to yield some sort of results in the Acquisition->Google Play Referral section of my Analytics account and have something to do with testCampaign. I do not see anything in my account not even after 24 hours (not sure that's still required but I remember it used to be for GA).
If anyone knows of a piece that I'm missing or why it would not be showing up in my account, please point me in the right direction. Thank you.
EDIT:
Here is my tracker code in my extended Application Class:
private static final String TRACKER_TAG = "GA Tracker";
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
public enum TrackerName {
APP_TRACKER // Tracker used only in this app.
}
synchronized Tracker getTracker(TrackerName trackerEnum) {
Log.d(TRACKER_TAG, "Getting GA tracker");
if (!mTrackers.containsKey(trackerEnum)) {
Log.d(TRACKER_TAG, "Creating new GA tracker");
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
analytics.getLogger().setLogLevel(LogLevel.VERBOSE);
Tracker t = analytics.newTracker(R.xml.global_tracker);
mTrackers.put(trackerEnum, t);
}
return mTrackers.get(trackerEnum);
}

Maybe you already did it but,
did you set your Tracking ID at >>>>> <string name="ga_trackingId">MY-TRACKING-ID</string> ?

Related

Google Analytics for Android failing to send any data

From Application onCreate(), to test event/screen logging:
public static void logUserAction(String eventName) {
Timber.i("Logging to Google Analytics");
Tracker t = getTracker();
t.setScreenName(eventName);
t.send(new HitBuilders.ScreenViewBuilder().build());
t.send(new HitBuilders.EventBuilder()
.setCategory("Event")
.setAction(eventName)
.setLabel(eventName)
.setValue(1)
.build());
}
synchronized static Tracker getTracker() {
if (googleAnalyticsTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(application);
googleAnalyticsTracker = analytics.newTracker(R.xml.global_tracker);
}
return googleAnalyticsTracker;
}
Config file, global_tracker.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="ga_sessionTimeout">300</integer>
<string name="ga_trackingId">UA-ACTUAL_VALUE_USED_HERE</string>
</resources>
Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Build file
compile 'com.google.android.gms:play-services-analytics:7.0.0'
The UA tracking code I'm using is definitely correct. The project builds and executes, however although the log message is shown to confirm the code is called, absolutely nothing happens in debug or release builds. No data is showing in Analytics, and there is nothing in Logcat to guide me.
What did I miss?
Like my comment said, you have to wait some times after the "Google Analytics ID" creation, before you can view any reports.

Simple case of using Google Analytics for android doesn't works

I'm having a really hard times using Google Analytics in my android application.
I don't need anything complicated, all I want to do is to receive general information about my users, and to receive reports whenever the application crushes.
I performed the following steps:
I created an Application class which contains a private Tracker object.
inside the onCreate function I initialized it.
public class MyApplication extends Application{
private Tracker googleAnalyticsTracker;
#Override
public void onCreate() {
super.onCreate();
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
googleAnalyticsTracker = analytics.newTracker(R.xml.google_analytics_tracker);
googleAnalyticsTracker.enableAutoActivityTracking(true);
googleAnalyticsTracker.enableExceptionReporting(true);
}
}
I created an xml file in order to generate the tracker (google_analytics_tracker.xml), as you can see here:
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-*THE ID WHICH I RECIVED*</string>
nevertheless - whenever I execute the application I can't see anything in my google analytics dashboard. Whenever the program crushes - I can't see anything in the google analytics Behavior/'crashes and exceptions' as wel.(I'm looking
does someone have a clue what could be the problem?
Thanks a lot
Try the instructions on this page. You are missing a few things such as sending a screen view event as well as any activity code to getting the global tracker
https://developers.google.com/analytics/devguides/collection/android/v4/

google analytics doesn't show the active user in Real time overview

i have setup every thing in my app for using google analytics V4
and i get every things working and i can see it but when i go to real time overview in my mobile view i didn't see any active user
this is my tracker
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="TypographyDashes">
<integer name="ga_sessionTimeout">300</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="info.lifepast.MainActivity">MainActivity</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxx-3</string>
</resources>
and the application class is
public class Analytics extends Application {
private static final String PROPERTY_ID = "UA-xxxxx-3";
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}
HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker(PROPERTY_ID)
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker)
: analytics.newTracker(R.xml.ecommerce_tracker);
mTrackers.put(trackerId, t);
}
return mTrackers.get(trackerId);
}
}
and in my main activity on create i added this
Tracker t = ((Analytics) this.getApplication()).getTracker(
TrackerName.GLOBAL_TRACKER);
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(LogLevel.VERBOSE);
// Set screen name.
// Where path is a String representing the screen name.
t.setScreenName(getString(R.string.app_name));
// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());
and the manifest file
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="#xml/global_tracker"/>
any help?
I've been looking at the v4 analytics today, and have also had trouble getting screen views to post. Here are a couple things I've dug up during my investigations that may be helpful for you:
AppViewBuilder is deprecated in favor of ScreenViewBuilder (see the HitBuilders source code). This part of the documentation is, presumably, out of date. Edit Mar 6, 2015: it would appear that the linked documentation has now been updated to use ScreenViewBuilder.
If my interpretation of the documentation is correct, it should not be necessary to explicitly post screen views using a ScreenViewBuilder when the auto activity tracking feature is enabled (which I see is the case in your configuration file).
By default, the current date is not included in your Google Analytics stats. You can choose to include it by manually selecting a date range (see drop-down control at the top right of most GA pages).
Make sure you shorten the dispatch period for debug builds - by default, events are batched and sent every 30 minutes, but for testing it's ok to reduce this to a few seconds. See the answer from #vangoz for implementation details.
Hope some of that helps you.
Edit: related, but I see you've already posted there: Google Analytics API v4 for Android Does NOT Send Screen Views
For me it turns out Google Analytics only dispatch the data every 30 minutes by default. So changing the dispatch time for testing show the realtime data with some delay.
GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(15);
Reference: https://developers.google.com/analytics/devguides/collection/android/v4/dispatch

Mobile backend starter continuous query never returns

I've written an Android client for a mobile backend starter app according to this tutorial. Everything works up to the section implementing Continuous Queries.
I've written a query and I'm calling it from the correct place in the code (onPostCreate()), however the query never returns any data.
I don't believe this is an authentication problem because I'm able to make other calls successfully.
Here is the code which never returns a result:
CloudCallbackHandler<List<CloudEntity>> handler = new CloudCallbackHandler<List<CloudEntity>>() {
#Override
public void onComplete(List<CloudEntity> results) {
for (CloudEntity entity : results) {
UserLocation loc = new UserLocation(entity);
mUserLocations.remove(loc);
mUserLocations.add(loc);
drawMarkers();
}
}
#Override
public void onError(IOException e) {
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
}
};
CloudQuery query = new CloudQuery("UserLocation");
query.setLimit(50);
query.setSort(CloudEntity.PROP_UPDATED_AT, Order.DESC);
query.setScope(Scope.FUTURE_AND_PAST);
getCloudBackend().list(query, handler);
With the debugger I've verified that the getCloudBackend().list() line executes, but the onComplete() method is never hit, and neither is onError().
Here is an example of a call that works perfectly:
UserLocation self = new UserLocation(super.getAccountName(),
gh.encode(mCurrentLocation));
getCloudBackend().update(self.asEntity(), updateHandler);
Essentially, getCloudBackend().update() works, while getCloudBackend().list() does not.
I should also add that I've downloaded the full source from the github repo linked in the tutorial, and the same problem exists with that code.
I've also tried re-deploying the backend server multiple times.
Ok so I have finally fixed the problem! The issue is both in the manifest and in the class GCMIntentService.java
In the manifest the GCM is registered as a service and belongs to a package. By default this service is a part of the default package com.google.cloud.backend.android. When you create a new package and have all your client code in there, you need to move the GCMIntentService.java class into that new package and in the manifest modify the service and broadcast receiver
<service android:name="yourpackagename.GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="yourpackagename" />
</intent-filter>
</receiver>
Any other permission that comes with the default package name should also be updated to the main package name. This doesn't need to be modified if you're only going to use that one default package that comes with the mobile backend starter.
Regarding the GoogleAuthIOException I received that as well initially. So I redid all the steps to enable GCM and authentication. Things to keep in mind though are that I still followed the tutorial and went with Web Application -> Generic when registering the GCM server key and Web Client ID. Also another key thing to keep in mind when registering for the Android Client ID is that with your SHA1 fingerprint it also needs a package name. Again the package name has to be your main client package if you're using more than one package for your project. You can get the project number that goes in the Consts.java (and it's required to register GCM) from the old Google API console and the project ID from the new cloud console. The Web client ID also goes in the Consts.java file and also in that same file you have to enable auth by changing
public static final boolean IS_AUTH_ENABLED = false;
to
public static final boolean IS_AUTH_ENABLED = true;
Hope this helps.
So I am also getting the SAME EXACT problem you are. getCloudBackend().update() works for me, and not only with the geohasher class, I also tried to send updates to the cloud with myLocation.toString() where myLocation is a LatLng and it gets updated fine.
Sorry for not giving you the actual solution to your problem. It's a really odd situation that the same exact code worked in the Google I/O demo but not when we (and I followed the tutorial very thoroughly) actually try it out. I feel that this is a server problem if anything.
Thanks for reporting this -- sorry you are having a problem. THe most likely problem is in configuring GCM. Can you verify you have GCM enabled on the project and all the setup steps where done correctly? Maybe try to send a message and see if that works?

Activity Access Restriction Implementation in a Monodroid Application

I have a requirement where I need to restrict access to an activity of a Monodroid Application. Hence i tried a spike where the application IntentSayHello would have an access restricted Activity called SayHelloActivity. As the first step i defined the permission tag in the AndroidManifest.xml of the application as below:
...
...
</application>
<permission
android:name="intentsayhello.permission.SAYHELLO"
android:protectionLevel="signature" android:label="#string/permlbl_restricted"
android:description="#string/permdesc_restricted">
</permission>
</manifest>
Please note that i'm using protectionLevel = signature which means that any other application signed with the same certificate as IntentSayHello can only access the restricted activity.
Now i coded the SayHelloActivity as below:
[Activity(Label = "SayHelloActivity", MainLauncher = true, Icon = "#drawable/icon", Permission = "intentsayhello.permission.SAYHELLO")]
[IntentFilter(new string[] { "companyXYZ.intent.sayhello.MAIN" },Categories = new string[]{Intent.CategoryDefault},
DataMimeType = "vnd.companyXYZ.say.hello/vnd.companyXYZ.activity")]
public class SayHelloActivity : Activity
{
.....
.....
}
After this i tested with a client application by invoking SayHelloActivity of IntentSayHello through an implicit intent and i got SecurityException as expected.
Permission Denial: starting Intent { act=companyXYZ.intent.sayhello.MAIN typ=vnd.companyXYZ.say.hello/vnd.companyXYZ.activity cmp=IntentSayHello.IntentSayHello/intentsayhello.SayHelloActivity }
from ProcessRecord{4094f850 9126:DiffKeyHello.DiffKeyHello/10097} (pid=9126, uid=10097) requires intentsayhello.permission.SAYHELLO
Now if i want my client Application to be given access to the SayHelloActivity of the restricted application, i'm supposed sign my client application with the same keystore (certificate) and also mention in the AndroidManifest.xml of the client application as below:
...
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="intentsayhello.permission.SAYHELLO" />
</manifest>
But when i did both of this, the client application still could not invoke the SayHelloActivity and same SecurityException is thrown.
I would like to know the directions/solution to this issue.
Thanks
After Googling around, hit upon this page: http://lists.ximian.com/pipermail/mono-bugs/2011-January/108218.html
I took the cue from this page that the need to be put into the Client's AssemblyInfo.cs. The syntax would be:
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission("intentsayhello.permission.SAYHELLO")]
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
It worked from then on.
Further search in mono android forum, i found that another way of doing this is to explicitly add the androidmanifest.xml in the .csproj file as below:
<PropertyGroup>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
Either of the above solutions works, only i do not know which/both are correct practice.

Categories

Resources