Google Analytics V4 Campaign measurement Testing is not working

krishnamn picture krishnamn · Jul 9, 2014 · Viewed 7k times · Source

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

Answer

Russell picture Russell · Jul 16, 2014

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.