Skip to content

Commit

Permalink
6.1.20
Browse files Browse the repository at this point in the history
6.1.20
  • Loading branch information
amit-kremer93 authored Dec 10, 2020
2 parents 4ca80da + e509999 commit 0768595
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Versions
## 6.1.20
- Unified deep linking

## 6.1.10
- iOS SDK 6.1.1
- Android SDK 6.1.0
Expand Down
3 changes: 2 additions & 1 deletion Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The dev key is required for all apps and the appID is required only for iOS.<br/
| appId | Your iTunes [application ID](https://support.appsflyer.com/hc/en-us/articles/207377436-Adding-a-new-app#available-in-the-app-store-google-play-store-windows-phone-store) (iOS only) |
| isDebug | Debug mode - set to `true` for testing only |
|onInstallConversionDataListener| Set listener for SDK init response (Optional. default=true) |

|onDeepLinkListener| Set listener for DDL response (Optional. default=false) |
*Example:*

```javascript
Expand All @@ -65,6 +65,7 @@ appsFlyer.initSdk(
isDebug: false,
appId: '41*****44',
onInstallConversionDataListener: false, //Optional
onDeepLinkListener: true, //Optional
},
(res) => {
console.log(res);
Expand Down
55 changes: 52 additions & 3 deletions Docs/Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [Deep Linking](#deeplinking)
- [Deferred Deep Linking (Get Conversion Data)](#deferred-deep-linking)
- [Direct Deep Linking](#direct-deep-linking)
- [Unified deep linking](#Unified-deep-linking)
- [iOS Deeplink Setup](#iosdeeplinks)
- [Android Deeplink Setup](#android-deeplinks)
- [Uninstall](#measure-app-uninstalls)
Expand Down Expand Up @@ -41,12 +42,12 @@ appsFlyer.initSdk(



#### The 2 Deep Linking Types:
Since users may or may not have the mobile app installed, there are 2 types of deep linking:
#### The 3 Deep Linking Types:
Since users may or may not have the mobile app installed, there are 3 types of deep linking:

1. Deferred Deep Linking - Serving personalized content to new or former users, directly after the installation.
2. Direct Deep Linking - Directly serving personalized content to existing users, which already have the mobile app installed.

3. Unified deep linking - Unified deep linking sends new and existing users to a specific in-app activity as soon as the app is opened.<br>
For more info please check out the [OneLink™ Deep Linking Guide](https://support.appsflyer.com/hc/en-us/articles/208874366-OneLink-Deep-Linking-Guide#Intro).

### <a id="deferred-deep-linking"> 1. Deferred Deep Linking (Get Conversion Data)
Expand Down Expand Up @@ -103,6 +104,45 @@ appsFlyer.initSdk(/*...*/);

The `appsFlyer.onAppOpenAttribution` returns function to unregister this event listener. If you want to remove the listener for any reason, you can simply call `onAppOpenAttributionCanceller()`. This function will call `NativeAppEventEmitter.remove()`.

<hr/>

### <a id="Unified-deep-linking"> 3. Unified deep linking
In order to use the unified deep link you need to send the `onDeepLinkListener: true` flag inside the object that sent to the sdk.<br>
**NOTE:** when sending this flag, the sdk will ignore `onAppOpenAttribution`!<br>
For more information about this api, please check [OneLink Guide Here](https://dev.appsflyer.com/docs/android-unified-deep-linking)


```javascript
var onDeepLinkCanceller = appsFlyer.onDeepLink(res => {
console.log('onDeepLinking: ' + JSON.stringify(res));
console.log('status: '+ res.status);
console.log('type: '+ res.type);
})

appsFlyer.initSdk(
{
devKey: 'K2***********99',
isDebug: false,
appId: '41*****44',
onInstallConversionDataListener: true,
onDeepLinkListener: true
},
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
);
```

**Note:** The code implementation for `onDeepLink` must be made **prior to the initialization** code of the SDK.

**Important**

The `appsFlyer.onDeepLink` returns function to unregister this event listener. If you want to remove the listener for any reason, you can simply call `onDeepLinkCanceller()`. This function will call `NativeAppEventEmitter.remove()`.


<hr/>

### *Example:*
Expand All @@ -114,6 +154,10 @@ var onAppOpenAttributionCanceller = appsFlyer.onAppOpenAttribution((res) => {
console.log(res);
});

var onDeepLinkCanceller = appsFlyer.onDeepLink(res => {
console.log('onDeepLinking: ' + JSON.stringify(res));
})

var onInstallConversionDataCanceller = appsFlyer.onInstallConversionData(
(res) => {
if (JSON.parse(res.data.is_first_launch) == true) {
Expand Down Expand Up @@ -158,6 +202,11 @@ class App extends Component<{}> {
console.log('unregister onAppOpenAttributionCanceller');
onAppOpenAttributionCanceller = null;
}
if (onDeepLinkCanceller) {
onDeepLinkCanceller();
console.log('unregister onDeepLinkCanceller');
onDeepLinkCanceller = null;
}
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ appsFlyer.initSdk(
devKey: 'K2***********99',
isDebug: false,
appId: '41*****44',
onInstallConversionDataListener: true,
onInstallConversionDataListener: true, //Optional
onDeepLinkListener: true, //Optional
},
(result) => {
console.log(result);
Expand All @@ -134,6 +135,7 @@ appsFlyer.initSdk(
| appId | Your iTunes [application ID](https://support.appsflyer.com/hc/en-us/articles/207377436-Adding-a-new-app#available-in-the-app-store-google-play-store-windows-phone-store) (iOS only) |
| isDebug | Debug mode - set to `true` for testing only |
|onInstallConversionDataListener| Set listener for SDK init response (Optional. default=true) |
|onDeepLinkListener| Set listener for DDL response (Optional. default=false) |


## <a id="guides"> 📖 Guides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ public class RNAppsFlyerConstants {
final static String afEmails = "emails";

final static String afConversionData = "onInstallConversionDataListener";
final static String afDeepLink = "onDeepLinkListener";

final static String afSuccess = "success";
final static String afFailure = "failure";
final static String afOnAttributionFailure = "onAttributionFailure";
final static String afOnAppOpenAttribution = "onAppOpenAttribution";
final static String afOnInstallConversionFailure = "onInstallConversionFailure";
final static String afOnInstallConversionDataLoaded = "onInstallConversionDataLoaded";
final static String afOnDeepLinking = "onDeepLinking";

final static String INVITE_FAIL = "Could not create invite link";
final static String INVITE_CHANNEL = "channel";
Expand Down
107 changes: 73 additions & 34 deletions android/src/main/java/com/appsflyer/reactnative/RNAppsFlyerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import android.net.Uri;
import android.util.Log;

import androidx.annotation.NonNull;
import com.appsflyer.reactnative.RNUtil;
import com.appsflyer.deeplink.DeepLink;
import com.appsflyer.deeplink.DeepLinkListener;
import com.appsflyer.deeplink.DeepLinkResult;
import com.appsflyer.*;
import com.appsflyer.AFInAppEventType;
import com.appsflyer.AppsFlyerConversionListener;
Expand Down Expand Up @@ -38,6 +43,7 @@
import java.util.ArrayList;

import static com.appsflyer.reactnative.RNAppsFlyerConstants.*;
import static com.appsflyer.reactnative.RNAppsFlyerConstants.afOnDeepLinking;

public class RNAppsFlyerModule extends ReactContextBaseJavaModule {

Expand Down Expand Up @@ -120,6 +126,7 @@ private String callSdkInternal(ReadableMap _options) {
String devKey;
boolean isDebug;
boolean isConversionData;
boolean isDeepLinking;

AppsFlyerLib instance = AppsFlyerLib.getInstance();

Expand All @@ -136,8 +143,13 @@ private String callSdkInternal(ReadableMap _options) {
if (isDebug == true) {
Log.d("AppsFlyer", "Starting SDK");
}
isDeepLinking = options.optBoolean(afDeepLink, false);

instance.init(devKey, (isConversionData == true) ? registerConversionListener() : null, application.getApplicationContext());

if (isDeepLinking) {
instance.subscribeForDeepLink(registerDeepLinkListener());
}
Intent intent = null;
Activity currentActivity = getCurrentActivity();

Expand All @@ -152,6 +164,32 @@ private String callSdkInternal(ReadableMap _options) {
return null;
}

private DeepLinkListener registerDeepLinkListener() {
return new DeepLinkListener() {
@Override
public void onDeepLinking(@NonNull DeepLinkResult deepLinkResult) {
DeepLinkResult.Error dlError = deepLinkResult.getError();
if (dlError != null) {
sendEvent(reactContext, afOnDeepLinking, dlError.toString());
}
JSONObject deepLinkObj = new JSONObject();
try {
deepLinkObj.put("status", afSuccess);
deepLinkObj.put("deepLinkStatus", deepLinkResult.getStatus());
deepLinkObj.put("type", afOnDeepLinking);
deepLinkObj.put("data", deepLinkResult.getDeepLink().toString());
} catch (JSONException e) {
e.printStackTrace();
}
try {
sendEvent(reactContext, afOnDeepLinking,deepLinkObj.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
};
}

private AppsFlyerConversionListener registerConversionListener() {
return new AppsFlyerConversionListener() {

Expand All @@ -174,48 +212,49 @@ public void onConversionDataSuccess(Map<String, Object> conversionData) {
public void onConversionDataFail(String errorMessage) {
handleError(afOnInstallConversionFailure, errorMessage);
}
};
}

private void handleSuccess(String eventType, Map<String, Object> conversionData, Map<String, String> attributionData) {
JSONObject obj = new JSONObject();
private void handleSuccess(String eventType, Map<String, Object> conversionData, Map<String, String> attributionData) {
JSONObject obj = new JSONObject();

try {
JSONObject data = new JSONObject(conversionData == null ? attributionData : conversionData);
obj.put("status", afSuccess);
obj.put("type", eventType);
obj.put("data", data);
if (eventType.equals(afOnInstallConversionDataLoaded)) {
sendEvent(reactContext, afOnInstallConversionDataLoaded, obj.toString());
} else if (eventType.equals(afOnAppOpenAttribution)) {
sendEvent(reactContext, afOnAppOpenAttribution, obj.toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject data = new JSONObject(conversionData == null ? attributionData : conversionData);
obj.put("status", afSuccess);
obj.put("type", eventType);
obj.put("data", data);
if (eventType.equals(afOnInstallConversionDataLoaded)) {
sendEvent(reactContext, afOnInstallConversionDataLoaded, obj.toString());
} else if (eventType.equals(afOnAppOpenAttribution)) {
sendEvent(reactContext, afOnAppOpenAttribution, obj.toString());
}
} catch (JSONException e) {
e.printStackTrace();
}
}

private void handleError(String eventType, String errorMessage) {
JSONObject obj = new JSONObject();
private void handleError(String eventType, String errorMessage) {
JSONObject obj = new JSONObject();

try {
obj.put("status", afFailure);
obj.put("type", eventType);
obj.put("data", errorMessage);
sendEvent(reactContext, afOnInstallConversionDataLoaded, obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
try {
obj.put("status", afFailure);
obj.put("type", eventType);
obj.put("data", errorMessage);
sendEvent(reactContext, afOnInstallConversionDataLoaded, obj.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}

private void sendEvent(ReactContext reactContext,
String eventName,
Object params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
};
private void sendEvent(ReactContext reactContext,
String eventName,
Object params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}


private String logEventInternal(final String eventName, ReadableMap eventData) {

if (eventName.trim().equals("")) {
Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module "react-native-appsflyer" {
type: "onAppOpenAttribution"
| "onInstallConversionDataLoaded"
| "onAttributionFailure"
| "onInstallConversionFailure",
| "onInstallConversionFailure"
data: {
is_first_launch: "true" | "false";
media_source: string;
Expand All @@ -30,6 +30,7 @@ declare module "react-native-appsflyer" {
appId?: string; // iOS only
isDebug?: boolean;
onInstallConversionDataListener?: boolean;
onDeepLinkListener?: boolean;
timeToWaitForATTUserAuthorization?: number; // iOS only
}

Expand Down Expand Up @@ -62,6 +63,7 @@ declare module "react-native-appsflyer" {
onInstallConversionData(callback: (data: ConversionData) => any): () => void;
onInstallConversionFailure(callback: (data: ConversionData) => any): () => void;
onAppOpenAttribution(callback: (data: any) => any): () => void;
onDeepLink(callback: (data: any) => any): () => void;
initSdk(options: InitSDKOptions): Promise<string>;
initSdk(options: InitSDKOptions, successC: SuccessCB, errorC: ErrorCB): void;
logEvent(eventName: string, eventValues: object): Promise<string>;
Expand Down
25 changes: 25 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,31 @@ appsFlyer.onAppOpenAttribution = callback => {
};
};

appsFlyer.onDeepLink = callback => {

const listener = appsFlyerEventEmitter.addListener(
"onDeepLinking",
_data => {
if (callback && typeof callback === typeof Function) {
try {
let data = JSON.parse(_data);
callback(data);
} catch (_error) {
callback(new AFParseJSONException("Invalid data structure", _data));
}
}
}
);


eventsMap["onDeepLinking"] = listener;

// unregister listener (suppose should be called from componentWillUnmount() )
return function remove() {
listener.remove();
};
};

/**
* Anonymize user Data.
* Use this API during the SDK Initialization to explicitly anonymize a user's installs, events and sessions.
Expand Down
2 changes: 2 additions & 0 deletions ios/RNAppsFlyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static NSString *const IOS_14_ONLY = @"Feature only supported o
#define afOnAppOpenAttribution @"onAppOpenAttribution"
#define afOnInstallConversionFailure @"onInstallConversionFailure"
#define afOnInstallConversionDataLoaded @"onInstallConversionDataLoaded"
#define afDeepLink @"onDeepLinkListener"
#define afOnDeepLinking @"onDeepLinking"

// User Invites, Cross Promotion
#define afCpAppID @"crossPromotedAppId"
Expand Down
Loading

0 comments on commit 0768595

Please sign in to comment.