Android referral removed in analytics v3? - android

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.

Related

Getting broadcast if user installs app successfully using my intent play store url

I am working on app which suggested app. If user installs app successfully using my app then he gets reward in my app.
I am getting info about "com.android.vending.INSTALL_REFERRER" action of receiver which provides this but didn't get success...
So please help me with getting some full examples or other suggestion...
This is my code...
Button Click Event
btnInstallApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent goToMarket = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("market://details?id=com.idea.backup.smscontacts&referrer=tecksky"));
startActivity(goToMarket);
}
});
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tecksky.referrerdemo">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".receiver.ReferrerCatcher"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER"></action>
</intent-filter>
</receiver>
</application>
</manifest>
ReferrerCatcher.java
public class ReferrerCatcher extends BroadcastReceiver {
private static String referrer = "";
#Override
public void onReceive(Context context, Intent intent) {
referrer = "";
Bundle extras = intent.getExtras();
if (extras != null) {
referrer = extras.getString("referrer");
}
Log.e("REFERRER : ", referrer);
}
}
Hey Just see how it works I have implemented this in my app as well and works for me perfectly so I am posting you referral code:
Create separate class for receiving reference:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.gms.analytics.CampaignTrackingReceiver;
public class CustomReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
new CampaignTrackingReceiver().onReceive(context, intent);
Bundle b= intent.getExtras();
String referrerString = b.getString("referrer");
// Log.e("bundle", "bundle= " + referrerString+ " " + referrerString.substring(11, referrerString.length()));
SharedPrefManager.setPrefVal(context, Constants.REFERRAL, referrerString.substring(11, referrerString.length()));
}
}
This class will receive the referral that you have to save somewhere like I am saving it in SharedPrefrence. This broadcast will receive when the user will install app from play store and in "referrer" you will get info that which user pass this user the link to download app then from that referrer key you can give benefit to user who referred your app.
In manifest file add receiver Tag
<receiver
android:name="gcm.CustomReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
From backend you will get a link from server side for a particular user which you will hit to play store then something like
https://play.google.com/store/apps/details?id=com.example.app&referrer=utm_source=123456ref
Basically in your receiver class you are picking this utm_source and you have to send it to server side when user will sign up in you app. Which means it ll let know that from which reference which id has been generated.
Hope this helps you. Try this and let me know.

Referral linking in Android like mCent application

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.

Google Analytics Tracking with Android App Installs

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

How to get referrer URL for apps downloaded from outside the market

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>

BroadcastReceiver not catching the INSTALL_REFERRER broadcast

i created an app that has a BroadcastReceiver that catches a INSTALL_REFERRER broadcast.
When I'm installing the app with eclipse and creating a broadcast with adb I see that all work fine, the LogCat is displaying all that it should be.
But when I'm installing the app from the play store nothing is showing on the logcat.
If I understand correctly, the play store app should create a broadcast witch the app that is being installed supposed to catch, right?
Thats basicly what im doing:
public class SDK_Referrer extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals("com.android.vending.INSTALL_REFERRER"))
{
String referrer = intent.getStringExtra("referrer");
if (!(referrer == null || referrer.length() == 0))
{
// extracting the relevant data to Map
Log.d("SAMPLE", "Generating Ymid from referrel");
Map<String, String> referralmap =
createHashMapFromQueryString(referrer);
Log.d("SAMPLE", "Ymid is: " + referralmap.get("ymid"));
}
}
}
}
i only want to send someting to a server when the app is being installed.
Thanks!
You need to add the receiver to your manifest, so your app knows you have something listening for the broadcast. Something like this:
<receiver android:name="com.company.cool.SDK_Referrer" android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

Categories

Resources