Skip to content

Commit

Permalink
6.2.0
Browse files Browse the repository at this point in the history
6.2.0
  • Loading branch information
amit-kremer93 authored Jan 17, 2021
2 parents 71b1027 + 006154d commit a2ff15a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 98 deletions.
8 changes: 8 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Release Notes
### 6.2.0
Release date **January 17, 2021**
Release type: Major / **Minor** / Hotfix

**Overview and Highlights:**

- fix onAppOnAttribution behavior on Android and iOS. PLEASE read [Here](https://github.com/AppsFlyerSDK/appsflyer-cordova-plugin/blob/dev/RD-54921/fix-OAOA-behavior/docs/Guides.md#-ios-deeplink-setup)

### 6.1.30
Release date **January 11, 2021**
Release type: Major / **Minor** / Hotfix
Expand Down
64 changes: 52 additions & 12 deletions docs/Guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ window.plugins.appsFlyer.initSdk(options , onSuccess , onError);

### <a id="handle-deeplinking"> 2. Direct Deeplinking

When a deeplink is clicked on the device the AppsFlyer SDK will return the link in the [onAppOpenAttribution](https://support.appsflyer.com/hc/en-us/articles/208874366-OneLink-Deep-Linking-Guide#deep-linking-data-the-onappopenattribution-method-) method.
In order to implement deeplink with AppsFlyer, you must call `registerOnAppOpenAttribution` **before** `initSdk`<br>
For more information on deeplinks, please read [here](https://dev.appsflyer.com/docs/getting-started)




Expand Down Expand Up @@ -158,6 +160,7 @@ function onAppOpenAttributionError(err){


#### URI Scheme
Please follow the instructions [here](https://dev.appsflyer.com/docs/initial-setup-for-deep-linking-and-deferred-deep-linking#deciding-on-a-uri-scheme) <br>
In your app’s manifest add the following intent-filter to your relevant activity:
```xml
<intent-filter>
Expand All @@ -170,13 +173,26 @@ In your app’s manifest add the following intent-filter to your relevant activi


#### App Links
For more on App Links check out the guide [here](https://support.appsflyer.com/hc/en-us/articles/115005314223-Deep-Linking-Users-with-Android-App-Links#what-are-android-app-links).
Please follow the instructions [here](https://dev.appsflyer.com/docs/initial-setup-for-deep-linking-and-deferred-deep-linking#generating-a-sha256-fingerprint) <br>
In your app’s manifest add the following intent-filter to your relevant activity:
```xml
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="onelink-basic-app.onelink.me"
android:pathPrefix="/H5hv"
android:scheme="https" />
</intent-filter>
```

### <a id="ios-deeplink"> iOS Deeplink Setup

#### URI Scheme

For more on URI-schemes check out hte guid [here](https://support.appsflyer.com/hc/en-us/articles/208874366-OneLink-deep-linking-guide#setups-uri-scheme-for-ios-8-and-below)
For more on URI-schemes check out the guide [here](https://dev.appsflyer.com/docs/initial-setup-2#deciding-on-a-uri-scheme)

Add the following lines to your code to be able to track deeplinks with AppsFlyer attribution data:

Expand All @@ -191,9 +207,41 @@ var handleOpenURL = function(url) {
window.plugins.appsFlyer.handleOpenUrl(url);
}
```

Now you will get deep link information in the onAppOpenAttribution callback

#### If you are using Ionic+Capacitor or Ionic+Cordova:<br>
For plugin version **6.2.0** and up you need to add this to `didFinishLaunchingWithOptions`:
```
if (_AppsFlyerdelegate == nil) {
_AppsFlyerdelegate = [[AppsFlyerPlugin alloc] init];
}
[[AppsFlyerLib shared] setDelegate:_AppsFlyerdelegate];
```
And `#import "AppsFlyerPlugin.h"` to `AppDelegate.m`

For plugin version **6.1.30** and less, add `#import "AppsFlyerLib.h"` to `AppDelegate.m`

In both cases, you need to add this code before the `@end` tag:<br>
```
// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
[[AppsFlyerLib shared] handleOpenUrl:url options:options];
return YES;
}
// Open URI-scheme for iOS 8 and below
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[[AppsFlyerLib shared] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
return YES;
}
// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}
```


### Universal Links

For more on Universal Links check out the guide [here](https://support.appsflyer.com/hc/en-us/articles/208874366-OneLink-Deep-Linking-Guide#setups-universal-links).
Expand All @@ -216,14 +264,6 @@ Essentially, the Universal Links method links between an iOS mobile app and an a
</plist>
```

##### **Note**: Our plugin uses method swizzeling for

` - (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler; `

Now you will get deep link information in the onAppOpenAttribution callback

## <a id="uninstall"> Uninstall Measurement

### <a id="android-uninstall"> Android Uninstall Setup
Expand Down
8 changes: 8 additions & 0 deletions docs/RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Release Notes
### 6.2.0
Release date **January 17, 2021**
Release type: Major / **Minor** / Hotfix

**Overview and Highlights:**

- fix onAppOnAttribution behavior on Android and iOS. PLEASE read [Here](https://github.com/AppsFlyerSDK/appsflyer-cordova-plugin/blob/dev/RD-54921/fix-OAOA-behavior/docs/Guides.md#-ios-deeplink-setup)

### 6.1.30
Release date **January 11, 2021**
Release type: Major / **Minor** / Hotfix
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-appsflyer-sdk",
"version": "6.1.30",
"version": "6.2.0",
"description": "Cordova AppsFlyer SDK Plugin",
"cordova": {
"id": "cordova-plugin-appsflyer-sdk",
Expand Down
3 changes: 2 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-appsflyer-sdk"
version="6.1.30">
version="6.2.0">
<name>AppsFlyer</name>
<description>Cordova Plugin AppsFlyer</description>
<license>Apache 2.0</license>
Expand Down Expand Up @@ -50,6 +50,7 @@
<config-file target="AndroidManifest.xml" parent="/manifest" mode="merge">
<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" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/*/application">
<receiver android:name="com.appsflyer.MultipleInstallBroadcastReceiver" android:exported="true">
Expand Down
59 changes: 22 additions & 37 deletions src/android/com/appsflyer/cordova/plugin/AppsFlyerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.net.Uri;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.HashMap;
Expand Down Expand Up @@ -39,10 +41,10 @@ public class AppsFlyerPlugin extends CordovaPlugin {

private CallbackContext mConversionListener = null;
private CallbackContext mAttributionDataListener = null;
private Map<String, String> mAttributionData = null;
// private Map<String, String> mAttributionData = null;
private CallbackContext mInviteListener = null;
private Uri intentURI = null;
private Uri newIntentURI = null;
// private Uri newIntentURI = null;
private Activity c;

@Override
Expand Down Expand Up @@ -95,8 +97,6 @@ public boolean execute(final String action, JSONArray args, CallbackContext call
return logCrossPromotionImpression(args, callbackContext);
} else if ("logCrossPromotionAndOpenStore".equals(action)) {
return logAndOpenStore(args, callbackContext);
} else if ("resumeSDK".equals(action)) {
return onResume(args, callbackContext);
} else if ("getSdkVersion".equals(action)) {
return getSdkVersion(callbackContext);
} else if ("setSharingFilter".equals(action)) {
Expand Down Expand Up @@ -193,10 +193,6 @@ private boolean initSdk(final JSONArray args, final CallbackContext callbackCont

if (isConversionData == true) {

// if(mAttributionDataListener == null) {
// mAttributionDataListener = callbackContext;
// }

if (mConversionListener == null) {
mConversionListener = callbackContext;
}
Expand Down Expand Up @@ -253,6 +249,19 @@ private AppsFlyerConversionListener registerConversionListener(AppsFlyerLib inst

@Override
public void onConversionDataSuccess(Map<String, Object> conversionData) {
intentURI = c.getIntent().getData();
if (intentURI != null) {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
try {
AppsFlyerLib.getInstance().performOnAppAttribution(c.getApplicationContext(), new URI(intentURI.toString()));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
}
handleSuccess(AF_ON_INSTALL_CONVERSION_DATA_LOADED, conversionData, null);
}

Expand All @@ -263,10 +272,10 @@ public void onConversionDataFail(String errorMessage) {

@Override
public void onAppOpenAttribution(Map<String, String> attributionData) {
mAttributionData = attributionData;
intentURI = c.getIntent().getData();

handleSuccess(AF_ON_APP_OPEN_ATTRIBUTION, null, mAttributionData);
// mAttributionData = attributionData;
// intentURI = c.getIntent().getData();
// handleSuccess(AF_ON_APP_OPEN_ATTRIBUTION, null, mAttributionData);
handleSuccess(AF_ON_APP_OPEN_ATTRIBUTION, null, attributionData);

}

Expand Down Expand Up @@ -327,11 +336,9 @@ private void sendEvent(JSONObject params) {

if (
(params.optString("type") == AF_ON_ATTRIBUTION_FAILURE
|| params.optString("type") == AF_ON_APP_OPEN_ATTRIBUTION)
&& mAttributionDataListener != null) {
|| params.optString("type") == AF_ON_APP_OPEN_ATTRIBUTION) && mAttributionDataListener != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, jsonStr);
result.setKeepCallback(false);

mAttributionDataListener.sendPluginResult(result);
mAttributionDataListener = null;
} else if (
Expand All @@ -340,7 +347,6 @@ private void sendEvent(JSONObject params) {
&& mConversionListener != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, jsonStr);
result.setKeepCallback(false);

mConversionListener.sendPluginResult(result);
mConversionListener = null;
}
Expand Down Expand Up @@ -431,8 +437,6 @@ private boolean setAppUserId(JSONArray parameters, CallbackContext callbackConte
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, NO_CUSTOMER_ID));
return true;
}
// AppsFlyerLib.getInstance().setAppUserId(customeUserId);
//5.2.0 - setAppUserId replaced with setCustomerUserId
AppsFlyerLib.getInstance().setCustomerUserId(customeUserId);

PluginResult r = new PluginResult(PluginResult.Status.OK);
Expand Down Expand Up @@ -547,25 +551,6 @@ public void run() {
return true;
}

private boolean onResume(JSONArray parameters, CallbackContext callbackContext) {
Intent intent = cordova.getActivity().getIntent();
newIntentURI = intent.getData();

if (newIntentURI != intentURI) {
if (mAttributionData != null) {
PluginResult r = new PluginResult(PluginResult.Status.OK, new JSONObject(mAttributionData).toString());
callbackContext.sendPluginResult(r);
mAttributionData = null;
} else {
mAttributionDataListener = callbackContext;
sendPluginNoResult(callbackContext);
}

intentURI = newIntentURI;
}
return true;
}

// USER INVITE

/**
Expand Down
6 changes: 4 additions & 2 deletions src/ios/AppsFlyerPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "AppsFlyerLib.h"


@interface AppsFlyerPlugin : CDVPlugin <UIApplicationDelegate, AppsFlyerLibDelegate>
@interface AppsFlyerPlugin : CDVPlugin <UIApplicationDelegate, AppsFlyerLibDelegate, AppsFlyerDeepLinkDelegate>
// @interface AppsFlyerPlugin : CDVPlugin <UIApplicationDelegate, AppsFlyerTrackerDelegate>
- (void)initSdk:(CDVInvokedUrlCommand*)command;
- (void)resumeSDK:(CDVInvokedUrlCommand *)command;
Expand All @@ -12,6 +12,8 @@
- (void)getAppsFlyerUID:(CDVInvokedUrlCommand*)command;
- (void)onConversionDataSuccess:(NSDictionary*) installData;
- (void)onConversionDataFail:(NSError *) error;
- (void)onAppOpenAttribution:(NSDictionary*) attributionData;
- (void)onAppOpenAttributionFailure:(NSError *)_errorMessage;
- (void)logEvent:(CDVInvokedUrlCommand*)command;
- (void)registerUninstall:(CDVInvokedUrlCommand*)command;
- (void)handleOpenUrl:(CDVInvokedUrlCommand *)url;
Expand All @@ -28,7 +30,7 @@
- (void)setOneLinkCustomDomains:(CDVInvokedUrlCommand *)command;
@end


static AppsFlyerPlugin *_AppsFlyerdelegate;


// Appsflyer JS objects
Expand Down
41 changes: 8 additions & 33 deletions src/ios/AppsFlyerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ @implementation AppsFlyerPlugin

NSString* mConversionListener;
NSString* mAttributionDataListener;
NSString* mConversionListenerOnResume;
NSString* mInviteListener;
CDVPluginResult* mOAOAResult=nil;
BOOL isConversionData = NO;

- (void)pluginInitialize{}
Expand Down Expand Up @@ -107,24 +107,6 @@ - (void)initSdk:(CDVInvokedUrlCommand*)command
}
}

- (void)resumeSDK:(CDVInvokedUrlCommand *)command
{
[[AppsFlyerLib shared] start];


if (isConversionData == YES) {
CDVPluginResult* pluginResult = nil;
mConversionListenerOnResume = command.callbackId;

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
}
else {
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:SUCCESS];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
}
}

/**
* Sets new currency code. currencyId: ISO 4217 Currency Codes.
*/
Expand Down Expand Up @@ -207,6 +189,10 @@ - (void)registerOnAppOpenAttribution:(CDVInvokedUrlCommand *)command
mAttributionDataListener = command.callbackId;
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
if(mOAOAResult != nil){
[self.commandDelegate sendPluginResult:mOAOAResult callbackId:mAttributionDataListener];
mAttributionDataListener = nil;
}
}

/**
Expand Down Expand Up @@ -509,9 +495,6 @@ -(void) reportOnFailure:(NSString *)errorMessage withType:(NSString *)type{
}
}
else if([type isEqualToString:afOnInstallConversionFailure]){
if (mConversionListenerOnResume != nil) {
mConversionListenerOnResume = nil;
}

if(mConversionListener != nil){
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage];
Expand All @@ -529,22 +512,14 @@ -(void) reportOnFailure:(NSString *)errorMessage withType:(NSString *)type{
-(void) reportOnSuccess:(NSString *)data withType:(NSString *)type {

if([type isEqualToString:afOnAppOpenAttribution]){
mOAOAResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:data];
[mOAOAResult setKeepCallback:[NSNumber numberWithBool:NO]];
if(mAttributionDataListener != nil){
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:data];
[pluginResult setKeepCallback:[NSNumber numberWithBool:NO]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:mAttributionDataListener];
[self.commandDelegate sendPluginResult:mOAOAResult callbackId:mAttributionDataListener];
mAttributionDataListener = nil;
}
}
else if([type isEqualToString:afOnInstallConversionDataLoaded]){
if (mConversionListenerOnResume != nil) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:data];
[pluginResult setKeepCallback:[NSNumber numberWithBool:NO]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:mConversionListenerOnResume];

mConversionListenerOnResume = nil;
}

if(mConversionListener != nil){
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:data];
[pluginResult setKeepCallback:[NSNumber numberWithBool:NO]];
Expand Down
Loading

0 comments on commit a2ff15a

Please sign in to comment.