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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With