GithubHelp home page GithubHelp logo

isabella232 / appsflyer-segment-android-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from appsflyersdk/appsflyer-segment-android-plugin

0.0 0.0 0.0 347 KB

AppsFlyer's Android SDK - Segment Integration

Java 100.00%

appsflyer-segment-android-plugin's Introduction

AppsFlyer - Segment Integration

Maven Central


In order for us to provide optimal support, we would kindly ask you to submit any issues to [email protected]

When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , production steps, logs, code snippets and any additional relevant information.

Overview

AppsFlyer SDK provides app installation and event tracking functionality. We have developed an SDK that is highly robust (7+ billion SDK installations to date), secure, lightweight and very simple to embed.

You can track installs, updates and sessions and also track additional in-app events beyond app installs (including in-app purchases, game levels, etc.) to evaluate ROI and user engagement levels.


Built with AppsFlyer Android SDK v6.1.1

Table of content

Introduction

Segment makes it easy to send your data to AppsFlyer. Once you have tracked your data through Segment's open source libraries, the data is translated and routed to AppsFlyer in the appropriate format. AppsFlyer helps marketers to pinpoint targeting, optimize ad spend and boost ROI.

The AppsFlyer integration code is open-source on GitHub if you want to check it out.

Check out the Segment AppsFlyer docs here.

Getting Started

DashBoard Setup

To enable AppsFlyer in the Segment dashboard, follow these steps:

  1. Enter your unique AppsFlyer Dev Key, which is accessible from your AppsFlyer account, in Segment’s destination settings.
  2. After you build and release to the app store, your data is translated and sent to AppsFlyer automatically.

The Segment AppsFlyer integration is entirely handled through Segment's servers, so you don’t need to bundle AppsFlyer's iOS or Android SDKs. Your Segment SDK will be enough.

AppsFlyer supports the identify and track methods.

Setting up the SDK

2.1) Adding the Plugin to your Project

Add the AppsFlyer Segment Integration dependency to your app build.gradle file.

compile 'com.appsflyer:segment-android-integration:6.1.1'
compile 'com.android.installreferrer:installreferrer:2.1'

2.2) Setting the Required Permissions

The AndroidManifest.xml should include the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

2.2) Init AppsFlyer

static final String SEGMENT_WRITE_KEY = "<YOUR_KEY>";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Analytics.Builder builder = new Analytics.Builder(this , SEGMENT_WRITE_KEY)
.use(AppsflyerIntegration.FACTORY)

...
(optional)

.logLevel(Analytics.LogLevel.VERBOSE)
.recordScreenViews()
.trackAttributionInformation() // Install Attributed event
.trackApplicationLifecycleEvents() // Application Opened , Application Updated , Application Installed events
.build();

Analytics.setSingletonInstance(builder.build());

}

Adding .trackAttributionInformation() will send the Install Attributed event to AppsFlyer. Adding .trackApplicationLifecycleEvents() will send Application Opened , Application Updated and Application Installed events to AppsFlyer.

Track

When you call track, Segment translates it automatically and sends the event to AppsFlyer.

Segment includes all the event properties as callback parameters on the AppsFlyer event, and automatically translates properties.revenue to the appropriate AppsFlyer purchase event properties based on Segment's spec’d properties.

Finally, Segment automatically uses AppsFlyer’s transactionId-based de-duplication when sending an an orderId.

Purchase Event Example:

Map<String, Object> eventValue = new HashMap<String, Object>();
eventValue.put("productId","com.test.id");
eventValue.put("revenue","1.00");
eventValue.put("currency","USD");

Analytics analytics = Analytics.with(this);
Properties properties = new Properties();
properties.putAll(eventValue);

analytics.track("purchase", properties);

Note: AppsFlyer will map revenue -> af_revenue and currency -> af_currency.

Check out the Segment docs on track here.

Identify

When you identify a user, that user’s information is passed to AppsFlyer with customer user Id as AppsFlyer’s External User ID. Segment’s special traits recognized as AppsFlyer’s standard user profile fields (in parentheses) are:

customerUserId (Customer User Id)
currencyCode (Currency Code)

All other traits will be sent to AppsFlyer as custom attributes.

Analytics analytics = Analytics.with(this);

analytics.identify("a user's id", new Traits()
.putName("a user's name")
.putEmail("[email protected]"),
null);

Check out the Segment docs on indentify here.

Get Conversion Data

For Conversion data your should call the method below.

         AppsflyerIntegration.conversionListener  = new AppsflyerIntegration.ExternalAppsFlyerConversionListener() {
                    @Override
                    public void onConversionDataSuccess(Map<String, Object> map) {
                        // Process Deferred Deep Linking here
                        for (String attrName : map.keySet()) {
                            Log.d(TAG, "attribute: " + attrName + " = " + map.get(attrName));
                        }
                    }

                    @Override
                    public void onConversionDataFail(String s) {

                    }

                    @Override
                    public void onAppOpenAttribution(Map<String, String> map) {
                     // Process Direct Deep Linking here
                        for (String attrName : map.keySet()) {
                            Log.d(TAG, "attribute: " + attrName + " = " + map.get(attrName));
                        }
                    }

                    @Override
                    public void onAttributionFailure(String s) {

                    }
                };

In order for Conversion Data to be sent to Segment, make sure you have enabled "Track Attribution Data" in AppsFlyer destination settings:

Xnip2019-05-11_19-19-31

Unified deep linking

In order to implement unified deep linking, call the method below :

        AppsflyerIntegration.deepLinkListener = new AppsflyerIntegration.ExternalDeepLinkListener() {
            @Override
            public void onDeepLinking(@NonNull DeepLinkResult deepLinkResult) {
                //TODO handle deep link logic
            }
        };

For more information about unified deep linking, check here

Sample App

AppsFlyer has created a sample Android application that integrates AppsFlyer via Segment. Check it out at the Github repo.

appsflyer-segment-android-plugin's People

Contributors

af-fess avatar af-margot avatar benjaminaf avatar f2prateek avatar rocioetereo avatar shachar-af avatar shaharaf avatar sokoloff06 avatar wesfieldj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.