Google Analytics is storing the information I pass in the URL with utm_source, utm_campaign, and utm_medium. Now I am wondering how I grab that information when the user opens the application? I see this in my logs:'
03-18 20:19:48.633: I/GAV2(32317): Thread[GAThread,5,main]: Campaign found: utm_source=source value tracking tara&utm_medium=medium value tracking tara&utm_campaign=campaign value tracking tara androidlitetrackingtara
I have this in my applications manifest:
<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
<receiver
android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
I try to grab it from the intent, but the data is not there. Any ideas?
Make sure you are using the v3 SDK. Here is the instruction page:
https://developers.google.com/analytics/devguides/collection/android/v3/campaigns
If the INTENT_REFERRER doesn't work then try the Map example given later in the page.
Also, make sure you are giving enough time between downloading the app and the data showing up in GA. It can take up to ~24 hours for GA to show data.
Create your own broadcast receiver. Store data and pass it to google analytic later
public class InstallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.d("InstallReceiver", "onReceive");
try {
// get referrer value
Bundle extras = intent.getExtras();
if (extras != null) {
GoogleAnalytics.getInstance(context).getLogger().setLogLevel(LogLevel.VERBOSE);
String referrerValue = extras.getString("referrer");
// Handle data. Save it
Log.d("InstallReceiver", "referrerValue=" + referrerValue);
String afterDecode = URLDecoder.decode(referrerValue, "UTF-8");
String[] temp = afterDecode.split("&");
String agencyId = temp[0].replace("utm_source=", "");
Utils.saveAgencyId(context.getApplicationContext(), agencyId);
// transfer intent to google receiver.
new CampaignTrackingReceiver().onReceive(context, intent);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
Related
I am trying to get the referrer details from the URL when the app is downloaded via marketing URL. I have created a broadcast receiver with INSTALL_REFERRER intent filter.
My URL is:
http://hrt.glserv.info/com.cc.rummycentral?referrer=ewriewriwer&pid=vcommission_rummytest&af_r=http%3A%2F%2Frc.glserv.info%2Fdownload-apk%2F
// my Manifest code for receiver
<receiver android:name="com.cc.rummycentral.service.DownloadReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
DownloadReceiver class:
public class DownloadReceiver extends BroadcastReceiver
{
private static String TAG = "referrer";
public DownloadReceiver(){
Log.w(TAG, "INSIDE DownloadReceiver()");
}
#Override
public void onReceive(Context context, Intent intent)
{
try
{
Log.w(TAG, "INSIDE onReceive");
if (null != intent && intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))
{
Log.w(TAG, "YES, IT IS AN INSTALL EVENT");
String rawReferrer = intent.getStringExtra("referrer");
if (rawReferrer != null) {
String referrer = URLDecoder.decode(rawReferrer, "UTF-8");
Log.w(TAG,"HEY Received Referrer: " + referrer);
}
}
} catch (Exception var6) {
var6.printStackTrace();
Log.e(TAG, "EXP: "+var6.toString());
}
}
}
You have to install the app via playstore in order for this broadcast to work, Referrer broadcast is not a system broadcast, it is sent by playstore when an app is installed via playstore
There is a solution to make this scenario work. Make sure the app is downloaded from play store link . And generate the play store url from your third party website with referral id and website details and redirect to play store . This makes it works
I have to implement the referral linking functionality in my application like mCent application. For that I have done the following lines of code.
My application Manifest file. In the <application >..... </application> , I have done some entries for it.
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
<receiver
android:name=".receivers.InstallReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
And My BrodcastRecevier class is as follow , please check it.
public class InstallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String rawReferrer = intent.getStringExtra("referrer");
if (rawReferrer != null) {
trackReferrerAttributes(rawReferrer, context);
}
}
private void trackReferrerAttributes(String rawReferrer, Context context) {
String referrer = "";
try {
referrer = URLDecoder.decode(rawReferrer, "UTF-8");
} catch (UnsupportedEncodingException e) {
return;
}
if (Strings.isNullOrEmpty(referrer)) {
return;
}
Uri uri = Uri.parse('?' + referrer); // appends ? for Uri to pickup query string
String memberCode;
try {
referringMember = uri.getQueryParameter("mcode");
} catch (UnsupportedOperationException e) {
return;
}
SharedPreferences.Editor editor = context.getSharedPreferences(
BuildConfig.PACKAGE_NAME, Context.MODE_PRIVATE).edit();
if (!Strings.isNullOrEmpty(memberCode)) {
editor.putString(Constants.REFERRER_CODE, memberCode);
}
String referralMedium = uri.getQueryParameter("tc");
if (!Strings.isNullOrEmpty(referralMedium)) {
editor.putString("referral_medium", referralMedium);
}
editor.apply();
}
}
But i am not receiving any referral from the above code...
I have created the refferal link like this
https://play.google.com/store/apps/details?id=tv.CaseGaurd&referrer=ravindrakushwaha
Is there is any error in my referral link above OR friends , what am i doing wrong in my BroadcastRecevier class or in Manifest file
From this documentation I found that the action filter is (in manifest):
<!-- Used for install referrer tracking-->
<receiver android:name="YOUR_RECEIVER"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Also be sure that your Receiver is in that real package ".receivers.InstallReceiver", but package com.example.app.receivers;... is your package really com.example.app?
(I considered you to be using the Google Play Store app)... also, about your downvotes, this is likely to bad wording on your question, or that you are not showing effort about your question, finally, note that this is a "free to use community forum", and that people are random...
Finally, put a breakpoint in the Receiver, send a broadcast (using adb for instance), and test that you are really not getting the broadcast.
I need help with some Google Analytics tracking with Android app installs. I've tried researching this but haven't understood it all clearly.
So far, I have this in my AndroidManifest.xml:
<receiver
android:name="<IHaveMyPackageNameHere>.InstallReferrerReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Also, I have the following in my InstallReceiver class:
public class InstallReceiver extends BroadcastReceiver {
private static final String TAG = "InstallReferrerReceiver";
#Override
public void onReceive(Context context, Intent intent) {
AnalyticsTrackerFactory.setApiKey("");
HashMap<String,String> values = new HashMap<String, String>();
try {
if (intent.hasExtra("referrer")) {
String referrers[] = intent.getStringExtra("referrer").split("&");
for (String referrerValue : referrers) {
String keyValue[] = referrerValue.split("=");
values.put(URLDecoder.decode(keyValue[0]), URLDecoder.decode(keyValue[1]));
}
}
} catch (Exception e) {
}
Log.d(TAG, "referrer: " + values);
AnalyticsTrackerFactory.getTracker(context).event("Installed", values); } }
I've found some of this code online but cannot figure out how to implement it correctly. Basically, I'm stuck at setting an API key and sending the values to Google Analytics.
Can anyone guide me into the right direction? Thanks.
Google Analytics provides referrer receiver implementation. You don't need to implement it yourself. The instruction for adding campaign attribution are in this dev guide https://developers.google.com/analytics/devguides/collection/android/v4/campaigns
I've spent the last two days trying to find a workaround for this.
I need to pre-config my app depending on the referral and since google play is broadcasting an Install Referrer intent when an app is installed, I created my own receiver for this task. The code for the manifest declaration and the Receiver is:
Manifest declaration:
<receiver
android:name="my.package.CustomReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
And the simplified code of the CustomReceiver:
public class CustomReceiver extends BroadcastReceiver {
private static final String CAMPAIGN_SOURCE_PARAM = "utm_source";
#Override
public void onReceive(Context context, Intent intent) {
Log.d("debug", "waking receiver");
Uri uri = intent.getData();
getReferrerMapFromUri(uri);
new CampaignTrackingReceiver().onReceive(context, intent);
}
void getReferrerMapFromUri(Uri uri) {
MapBuilder paramMap = new MapBuilder();
// If no URI, return an empty Map.
if (uri == null) {
Log.d("debug", "intent null");
return;
}
if (uri.getQueryParameter(CAMPAIGN_SOURCE_PARAM) != null) {
// MapBuilder.setCampaignParamsFromUrl parses Google Analytics
// campaign
// ("UTM") parameters from a string URL into a Map that can be set
// on
// the Tracker.
paramMap.setCampaignParamsFromUrl(uri.toString());
Log.d("debug", paramMap.get(Fields.CAMPAIGN_SOURCE));
// If no source parameter, set authority to source and medium to
// "referral".
} else if (uri.getAuthority() != null) {
paramMap.set(Fields.CAMPAIGN_MEDIUM, "referral");
paramMap.set(Fields.CAMPAIGN_SOURCE, uri.getAuthority());
}
}
}
That's all. I am sending broadcast install intent with the adb shell command but it's not getting activated at all. I am using google analytics v3.
Thank you in advance!
I've tried this way. And it does work.( I am also using Google Analytics v3)
First, in manifest :
<!-- Used for Google Play Store Campaign Measurement-->;
<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
<receiver android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver" android:exported="true" >
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Second, add an CustomReceiver extends BroadcastReceiver
( In my case, I just copy and paste all the codes from developers )
package com.example.testanalytics;
import com.google.analytics.tracking.android.CampaignTrackingReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class CustomReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
// Pass the intent to other receivers.
// When you're done, pass the intent to the Google Analytics receiver.
new CampaignTrackingReceiver().onReceive(context, intent);
}
}
last step: in my activity( which I want to send messages to Google Analytics )
create an Intent and call sendBroadcast( Intent ) as follow:
Intent it = new Intent("com.android.vending.INSTALL_REFERRER");
it.setPackage("com.example.testanalytics");
it.putExtra("referrer", "utm_source%3Dyahoo%26utm_medium%3Dbanner+cpc%26utm_term%3Debook%26utm_content%3Dmy_content%26utm_campaign%3Dmy_campaign_name_2");
sendBroadcast(it);
And just get it.
I hope this may help you.
I've found some solutions to track referrer URL from the market, but my apps aren't in the market.
Is there a way to get the referrer URL for applications downloaded from private sites?
To get referrer, you need to register your receiver for that. After installation, a broadcast is fired which you need to catch by following code.
First take a look at Android Native Application Tracking Overview
1. Create a Receiver
public class ReferrerReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String referrerString = extras.getString("referrer");
Log.i("Home", "Referrer is: " + referrerString);
}
}
2. Register in Manifest file
<receiver android:name="your.package.name.ReferrerReceiver" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>