I started to Implement Campaign Measurement with Google Analytics V4 referring the link
https://developers.google.com/analytics/devguides/collection/android/v4/ .
Facing an issue when Tested Campign Measurement as mentioned in https://developers.google.com/analytics/solutions/testing-play-campaigns. Every time my logs showing "No Campaign data found"
I imported google Play services (Rev :18) in to my workspace and referred it in my project
Added below lines in my Manifest file
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<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" />
and also below code
<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>
later created global_tracker.xml file under res->xml. Below is my xml file
<?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>
<bool name="ga_debug">true</bool>
<string name="ga_logLevel">verbose</string>
<string name="ga_dryrun">true</string>
<!-- The screen names that will appear in reports -->
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-xxxxxxx-1</string>
</resources>
replaced Tracking Id with my tracking id
while testing campaign measurement, i first installed my app on to my device (Moto G (4.4.2)) through adb install. Made sure the app is not running and broadcasted the intent as mentioned in the above Link . i got success log when broadcasted the intent.
Intent
E:\xxxxxxx\adt-bundle-windows-x86_64-20140321\sdk\platform-tools
>adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <My Package name>/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source=testsource"
Response:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=<My Package name>
>/com.google.android.gms.analytics.CampaignTrackingReceiver (has extras) }
Broadcast completed: result=0
When i opened my application i always got " I/GAV2(7342): Thread[GAThread,5,main]: No campaign data found." error in my logs.
Can please someone let me know why am i not getting Campaign data ? where i am going wrong.
Also, why it is Showing "GAV2" in logs when i am using GAV4
GA Logs:
07-09 12:59:26.542: W/GAV2(20502): Thread[main,5,main]: Need to call initialize() and be in fallback mode to start dispatch.
07-09 12:59:31.568: I/GAV2(20502): Thread[GAThread,5,main]: No campaign data found.
Note: This is the first time i am working with Google Analytics. As i want to check whether i am receiving Campaign data or not first, i didn't implemented any trackers to GA
Edit : When i manually trigger the Broadcast intent on button click in my App. I am able to see "Campaign found" log when i restarted my app. But the same not happening when triggered intent using "adb shell" command as mentioned above. I doubt may be intent is not reaching to my device . Is there any way to find whether the intent is received or not ?
Please help
1> ok for the starters you are mixing two things.
this link is for Google Analytics-v4 https://developers.google.com/analytics/devguides/collection/android/v4/
and this link https://developers.google.com/analytics/solutions/testing-play-campaigns is not for v4( the page is too old, there was no GAV4 when this page was published.
2> Check the physical-device(Google play services) version and update it to 5.0, if not already done.
3> you dont need the boiler plate code mentioned below. I think this is for GAV3 and not GAV4
<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>
for more clarity on code check this link. No campaign data found. Using Google Analytics v4
4> Specifically for GAV4(with my own exprience), its ok to see the error "No Campaign data found". try to run the code in verbose mode and you will see that GAV4 is making connections to its host.
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(LogLevel.VERBOSE);
5> Do not turn on the dry_run, you will not see the data on Google Analytics. By default this is off.
6> finally, inside Google Analytics see under "Real-time" for live hits.
hope this helps.
I was having the same issue with an extra error of ClassNotFound sometimes.
First i suggest to see Nishant's response and here are a couple more thing to check if they solve your problem:
1) If you are having more than one BroadcastReceiver:
1.1) Ensure you don't! Keep only one and add the intent-filter to that one:
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"/>
<receiver android:name="com.example.MyScheduleReceiver"
android:exported="true">
<intent-filter >
<action android:name="android.intent.action.ACTION_USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE"/>
<action android:name="android.intent.action.ACTION_SCREEN_OFF" />
<action android:name="android.intent.action.ACTION_SCREEN_ON" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
1.2) Then at end of the BroadcastReceiver send the intent to the right receiver:
#Override
public void onReceive(Context context, Intent intent) {
//Do your code for the other intents
new CampaignTrackingReceiver().onReceive(context, intent);
}
2) Calling the right Analytics version is also an issue when reading Google's tutorial because some links redirect you to older versions of the library all the time. If you are using v4 then:
2.1) Ensure not be including the libGoogleAnalyticsV2.jar
2.2) Double check that you are writing com.google.android.gms.analytics.CampaignTrackingService all the times and on all the imports.
3) When using the ADB to check if its working verify the previous points. On the above example, the right line to call the ADB will be:
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.example/com.example.MyScheduleReceiver --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
For this make CustomReceiver and from that send intent to google CampaignTrackingReceiver in GoogleAnalyticsv4.
By this you will get CampaignFound in logs
public class CustomCampaignTrackingReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
new CampaignTrackingReceiver().onReceive(context, intent);
}
}
Install the apk file to you device.
adb install filename.apk
Type the following adb command:
..\sdk\platform-tools>adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n your.package.name/com.google.android.gms.analytics.CampaignTrackingReceiver --es "referrer" "utm_source=testSource"
Note that the command given in this link has a V3 Receiver.
Check logcat. The Campaign Found message should be there. Make sure the app is not running when the referrer is being sent. The app should be launched only after it is done.
Might be useful to someone... I was getting GAv4: Discarding hit. Missing tracking id parameter because instead of:
GoogleAnalytics.getInstance(context).newTracker(R.xml.app_tracker);
I've added
GoogleAnalytics.getInstance(context).newTracker(R.string.ga_trackingId);
Note the difference xml.app_tracker vs string.ga_trackingId!
Use xml.app_tracker configuration file!
As I checked in my last implementation. Maybe the log can be broken. I received "No campaign data found" in the logs, but I see real data in the web console.
I am using v4, and my manifest looks like this:
<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>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
Good luck
Related
Hi I'm Android developer, and I met a challenge about using Google Analytics Campaign using SDK v4.x.
I have refered to the following URL
https://developers.google.com/analytics/solutions/testing-play-campaigns
And I finished the step of 'Broadcasting an INSTALL_REFERRER Intent'
Because I could see this message successfully.
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER
cmp=com.example.analyticsecommtest/com.google.analytics.tracking.android.AnalyticsReceiver
(has extras) }
Broadcast completed: result=0*
But I found this log :
Thread[GAThread,5,main]: No campaign data found.
The reference URL said, the log means that my Google Play Campaign Measurement implementation is not working correctly. Thus I tried to fix the work as checking out troubleshooting section.
there are several reasons.
The INSTALL_REFERRER intent was not broadcast
-> I finished it as I told
The Google Analytics Receiver did not receive the intent
-> I implemented CampaignTracking correctly, I think.
and only CampaignTrackingReceiver uses INSTALL_REFERRER.
Now, What can I do to implement CampaignTracking successfully?
and do I need to implement Receiver.class that extends BroadcastReceiver? (even I use SDK v4.x)
one more question, if I send setCampaignParamsFromUrl on my application code, what happen is going on?**
Here is AndroidManifast xml code.
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true" />
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
please answer anyone who has used Google Analytics Campaign successfully.
Thank you.
I am trying to implement google analytics service to android app using the following documentation provided in sdk:
https://developers.google.com/analytics/devguides/collection/android/v4/
I am unable to see any information in the analytics admin site.
While the app is running, I am seeing following debug message
"AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See https://developers.google.com/analytics/devguides/collection/android/v4/ for instructions."
Can you please suggest me how to register this service?
I am not sure if acting on this warning will solve the issue you're having (i.e. not seeing any information in the Analytics admin site).
Anyway, here is what you should add to AndroidManifest.xml inside the application tag if you want to get rid of this warning:
<!-- Optionally, register AnalyticsReceiver and AnalyticsService to support background
dispatching on non-Google Play devices -->
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!-- Optionally, register CampaignTrackingReceiver and CampaignTrackingService to enable
installation campaign reporting -->
<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>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
You don't have to add all of this, just add what you need. In your case, you apparently just need to add the AnalyticsService service.
Source: https://developer.android.com/reference/com/google/android/gms/analytics/GoogleAnalytics.html
add this on manifest
<service android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
Karim explained it well, but it won't work until you give the Wake lock permission in the manifest.
<uses-permission android:name="android.permission.WAKE_LOCK" />
Google v4 dispatch reference.
I had quite similar problem - message about AnalyticsService looks like your device doesn't have Google Services, but it wasn't true for me. However, I've realized that I couldn't be sure that this log'd been invoked from my app - log looked like that: 10173-10192/? V/GAV4, so package name was hidden.
To see logs from Google Analytics, you should change log level to verbose:
GoogleAnalytics.getInstance(this).getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
It will help you to analyze, what is a cause of your problems.
I wrote an app that has the following BroadcastReceiver :
<receiver
android:exported="true"
android:name="com.package.InstallReferrerReceiver" >
<intent-filter >
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
The intent fires fine when I am using
am broadcast -a com.android.vending.INSTALL_REFERRER
-n com.example.gatestapp/com.google.analytics.tracking.android.CampaignTrackingReceiver
--es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
But, on uploading this app as a Beta version, it doesnt seem to fire (in the receiver,it should contact a webservice).
I made the link and sent it to people in messages.They opened the referral links in the browser.
What could the problem be ? Is it that it wont work for Beta? or , is there any 'correct' way of downloading from the play store via play ?
I am newer to Android and trying to implement some applications using Google Cloud Messaging. I originally had set up a single application, and have now split my application into two (a server and a client).
My GCM intents were working, but when I split my application, I divided packages up. My old application was <base.package> and now the two are <base.package>.client and <base.package>.server.
Now, on my client application (which receives the broadcast), in my log files I see:
11-24 11:24:47.978: W/GCM/DMM(14909): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=<base.package> (has extras) }
11-24 11:24:47.978: W/GCM/DMM(14909): Receiver package not found, unregister application <base.package> sender <project.id>
My manifest is as follows:
<!-- Needed for the GCM messaging service -->
<permission
android:name="<base.package>.client.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<base.package>.client.permission.C2D_MESSAGE" />
<!-- Needed to receive GCM broadcasts -->
<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="<base.package>.client" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" >
</service>
So it looks like what has happened, is my old application with <base.package> is not allowing my new application with <base.package>.client to register? Is this on on the Google server side or somehow within my Eclipse project? How can I clear it?
I have a feeling I could just create a new Google console project project and start from scratch with a new project ID, but I guess I wouldn't learn at all that way :-)
Btw you can start from scratch but thats not necessary as if just create a new console project with .client package name and use that project id and that will do the job...
You included only part of the relevant manifest declarations in your question. Near the top of your manifest, you should have <permission> and <uses-permission> declarations that contain <base.package>.permission. You should change them to <base.package>.client.permission.
I originally asked this question, about passing parameters through a market link into my app on install.
Everyone seems to be saying to create a BroadcastListener with the intent-filter action of com.android.vending.INSTALL_REFERRER. All the documentation on that seems to imply this is a capability of Google Analytics (the documentation is in v1, but I can only download v2 SDK at this point... so that's what I am using). I can't get these links to pass data through. I have my full manifest and my broadcast listener. I have included Google Analytics just in case that was a requirement.
Google Analytics Reference
Generated link to market from here
Link to my app in the store
Link with parameters in the store
It doesn't work at all. My broadcast listener is never called, nothing gets printed out in the logs. Help!
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robotsidekick.webbrowser"
android:versionCode="4"
android:versionName="4.0">
<uses-sdk android:minSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity
android:name="WebBrowser"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver
android:exported="true"
android:name="com.robotsidekick.webbrowser.InstallReceiver">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
</application>
</manifest>
Broadcast Listener
public class InstallReceiver extends BroadcastReceiver
{
private static final String TAG = "InstallReceiver";
public void onReceive(Context context, Intent intent)
{
Log.e(TAG, "Context: " + context);
Bundle extras = intent.getExtras();
if (extras != null)
{
Log.e(TAG, "Extras:");
for (String keys : extras.keySet())
{
Log.e(TAG, keys + " -> " + extras.get(keys));
}
}
else
{
Log.e(TAG, "Extras are null");
}
}
}
So xbakesx says that it seems to work if his receiver extends com.google.analytics.tracking.android.AnalyticsReceiver.
I think the key is that the intent has permissions for ...AnalyticsReceiver and so no other class that is not extending it can pick up the intent. If you look at their test broadcast https://developers.google.com/analytics/solutions/testing-play-campaigns it does appear specific for that class.
If you change that test broadcast so that your class replaces com.google.analytics.tracking.android.AnalyticsReceiver you can then receive it. The biggest problem is they seemed to have locked down this class in beta 4 or 5. If anyone has a link to beta 3 we could test this, or if xbakex could confirm with playing around with the new jars that would rock!
Update:
BAM! So permissions are not an issue. I created a test project and used the PlayStores alpha testing to test out referrer links, which you can build here: https://developers.google.com/analytics/devguides/collection/android/v2/campaigns.
The cool thing is you don't need any GA jar at all! Checkout my test project here: https://github.com/twotoasters/AnalyticsTest/ This project also shows you how to parse the link to get all of the information that you need.
After many failed attempts i could finally see the passed referral parameters in logcat.
Along the way, i figured out a few things, i am not too sure if i am doing it rite or wrong, but for some reasons, these worked. If someones still stuck, they can get some pointers from my learnings.
A. creating a custom BroadcastReceiver where you can ready the intent. (this will executed, only once you have successfully fired the Install_referrer intent from the ADB for testing). Also make sure, if you need to do a post back of the referrer information to a server, it will have to be on a separate thread.
public class CustomBR extends BroadcastReceiver {
private static final String D_TAG = "BR";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(D_TAG, "CustomReceiver onReceive (context, intent)");
try {
String referrer = intent.getStringExtra("referrer");
// pass the referrer string to another singleton class to post it to server
HandleServerComm.getInstance().postData(referrer);
} catch (Exception e) {
e.printStackTrace();
}
}
}
B. update the androidmanifest.xml file to reflect the custom receiver you have created
<receiver android:exported="true" android:name="com.example.myapp.CustomBR" android:enabled="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
C. make sure you have adb installed correctly to test this on local environment. you will also need a device to be connected via USB with remote debugging enabled.
D. run the adb shell command to remotely broadcast a install_referrer on the device and pass it parameters.
The command is
adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.example.myapp/.CustomBR --es "token" "sample_token" --es "source" "banner"
Note that the important parts of this command is com.example.myapp/.CustomBR and --es "token" "sample_token" where --es is the additional parameters that are being sent along with the intent. the first quote after --es is the querystring / parameter name and the second quote is the value. Similarly, if you have to add more than one value, replicate it as shown in the example above.
E. Finally the most important part that kept me frustrated all the while - the app installed on the device itself. Your app should be installed on the device but not running at all. To do this, you will have to "Force Close" the app and then fire the adb shell command to fire up the install_referrer. thats when, you should see the logcat light up with required data.
F. You might also want to uninstall the update on google play store app and restore it to factory settings. at times (not confirmed) the version of google play determines what data is being passed to the app via the install_referrer or if the referrer is called at all.
Hope this helps someone.
Registering a BroadcastReceiver in your app's AndroidManifest.xml with an intent filter is the correct solution to app install referrals whether using Google Analytics or not.
<receiver
android:exported="true"
android:name="com.yourcompany.package.receivers.InstallReceiver">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
If you're already using Google Analytics you simply specify android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" for your receiver and the following service as well. Both are included in the Google Play services client library so there isn't any Java code to write. If you haven't already, you will also have to go through the initial setup instructions for Google Analytics for your App.
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
If you're not using Google Analytics then you'll need to define your own BroadcastReceiver in your java code. You will want it to inspect the extras on the received intent when implementing onReceive.
The referrer parameter in the URL that is received by Google Play (the store) is the only parameter passed through to the Android app for the referral so it's very common to encode a few parameters within it. For Google Analytics that means industry standard utm_* parameters, but you can use others. Here's the test adb command I typically use for opening Google Play to install and test the full flow.
adb shell "am start -a android.intent.action.VIEW -d \"https://play.google.com/store/apps/details?id=com.somecompany.package&referrer=utm_source%253Dtest_campaign_source%2526utm_medium%253Dtest_campaign_medium%2526utm_term%253Dtest_campaign_term%2526utm_content%253Dtest_campaign_content%2526utm_campaign%253Dtest_campaign_name\""
Testing Notes:
When testing this flow it's very important to check that the above command resulted in an output where the Intent was logged to your console with the FULL referrer information still attached. It's very easy for the escaping to be incorrect and silently drop the referrer.
Remember that the APK must have been installed by Google Play (the Store) on to the device you're testing on (you can't side-load). Therefore, you usually need to use your Alpha distribution channel in Google Play to test this.
It's important to note that if the device is >= Honeycomb MR1 the INSTALL_REFERRER intent is broadcast after the App is first launched rather than after the app is installed.
You will need to reinstall your app every time you need to test the referrer flow.
Install referrals are tracked when the app is installed from the Android Google Play app, but not the web version of the store.