Skip to content

Commit

Permalink
startSdk and performOnDeepLinking
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-kremer93 committed Aug 22, 2022
1 parent f915a17 commit f4e4d0c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ local.properties
android/gradlew.bat
.vscode
android/gradle
android/gradlew
android/.project

# node.js
Expand All @@ -50,7 +51,7 @@ buck-out/
android/app/libs
android/keystores/debug.keystore


.watchmanconfig
coverage/
package-lock.json

Expand Down
30 changes: 30 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,36 @@ describe("Test appsFlyer API's", () => {
appsFlyer.sendPushNotificationData({ foo: 'bar' });
expect(RNAppsFlyer.sendPushNotificationData).toHaveBeenCalledTimes(1);
});

test('it calls appsFlyer.appendParametersToDeepLinkingURL(dummy-url, foo)', () => {
appsFlyer.appendParametersToDeepLinkingURL('dummy-url', 'foo');
expect(RNAppsFlyer.appendParametersToDeepLinkingURL).toHaveBeenCalledTimes(0);
});

test('it calls appsFlyer.appendParametersToDeepLinkingURL(dummy-url, boolean)', () => {
appsFlyer.appendParametersToDeepLinkingURL('dummy-url', true);
expect(RNAppsFlyer.appendParametersToDeepLinkingURL).toHaveBeenCalledTimes(0);
});

test('it calls appsFlyer.appendParametersToDeepLinkingURL(dummy-url, {})', () => {
appsFlyer.appendParametersToDeepLinkingURL('dummy-url', {});
expect(RNAppsFlyer.appendParametersToDeepLinkingURL).toHaveBeenCalledTimes(1);
});

test('it calls appsFlyer.setDisableNetworkData(true)', () => {
appsFlyer.setDisableNetworkData(true);
expect(RNAppsFlyer.setDisableNetworkData).toHaveBeenCalledTimes(1);
});

test('it calls appsFlyer.startSdk()', () => {
appsFlyer.startSdk();
expect(RNAppsFlyer.startSdk).toHaveBeenCalledTimes(1);
});

test('it calls appsFlyer.performOnDeepLinking()', () => {
appsFlyer.performOnDeepLinking();
expect(RNAppsFlyer.performOnDeepLinking).toHaveBeenCalledTimes(1);
});
});

describe('Test native event emitter', () => {
Expand Down
4 changes: 4 additions & 0 deletions __tests__/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jest.mock('../node_modules/react-native/Libraries/BatchedBridge/NativeModules',
setSharingFilterForPartners: jest.fn(),
setCurrentDeviceLanguage: jest.fn(),
sendPushNotificationData: jest.fn(),
appendParametersToDeepLinkingURL: jest.fn(),
setDisableNetworkData: jest.fn(),
performOnDeepLinking: jest.fn(),
startSdk: jest.fn(),
},
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public class RNAppsFlyerModule extends ReactContextBaseJavaModule {

private ReactApplicationContext reactContext;
private Application application;
private String personalDevKey;

public RNAppsFlyerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
this.application = (Application) reactContext.getApplicationContext();
this.personalDevKey = "";
}

@Override
Expand Down Expand Up @@ -128,13 +130,16 @@ private String callSdkInternal(ReadableMap _options) {
boolean isDebug;
boolean isConversionData;
boolean isDeepLinking;
boolean isManualStartMode;

AppsFlyerLib instance = AppsFlyerLib.getInstance();
JSONObject options = RNUtil.readableMapToJson(_options);
devKey = options.optString(afDevKey, "");
if (devKey.trim().equals("")) {
return NO_DEVKEY_FOUND;
}
this.personalDevKey = devKey;

isDebug = options.optBoolean(afIsDebug, false);
instance.setDebugLog(isDebug);

Expand All @@ -143,22 +148,15 @@ private String callSdkInternal(ReadableMap _options) {
Log.d("AppsFlyer", "Starting SDK");
}
isDeepLinking = options.optBoolean(afDeepLink, false);
isManualStartMode = options.optBoolean("manualStart", false);

instance.init(devKey, (isConversionData == true) ? registerConversionListener() : null, application.getApplicationContext());
if (isDeepLinking) {
instance.subscribeForDeepLink(registerDeepLinkListener());
}
Intent intent = null;
Activity currentActivity = getCurrentActivity();

if (currentActivity != null) {
// register for lifecycle with Activity (automatically fetching deeplink from Activity if present)
instance.start(currentActivity, devKey);
} else {
// register for lifecycle with Application (cannot fetch deeplink without access to the Activity,
// also sending first session manually)
instance.logEvent(application, null, null);
instance.start(application, devKey);
if (!isManualStartMode) {
startSdk();
}
return null;
}
Expand Down Expand Up @@ -262,6 +260,20 @@ private void sendEvent(ReactContext reactContext,
.emit(eventName, params);
}

@ReactMethod
public void startSdk() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
// register for lifecycle with Activity (automatically fetching deeplink from Activity if present)
AppsFlyerLib.getInstance().start(currentActivity, this.personalDevKey);
} else {
// register for lifecycle with Application (cannot fetch deeplink without access to the Activity,
// also sending first session manually)
AppsFlyerLib.getInstance().logEvent(this.application, null, null);
AppsFlyerLib.getInstance().start(this.application, this.personalDevKey);
}
}

@ReactMethod
public void logEvent(
final String eventName, ReadableMap eventData,
Expand Down Expand Up @@ -766,6 +778,21 @@ public void appendParametersToDeepLinkingURL(String contains, ReadableMap parame
public void setDisableNetworkData(Boolean disabled) {
AppsFlyerLib.getInstance().setDisableNetworkData(disabled);
}

@ReactMethod
public void performOnDeepLinking() {
Activity activity = getCurrentActivity();
if (activity != null) {
Intent intent = activity.getIntent();
if (intent != null) {
AppsFlyerLib.getInstance().performOnDeepLinking(intent, this.application);
} else {
Log.d("AppsFlyer", "performOnDeepLinking: intent is null!");
}
} else{
Log.d("AppsFlyer", "performOnDeepLinking: activity is null!");
}
}

@ReactMethod
public void addListener(String eventName) {
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ declare module "react-native-appsflyer" {
onInstallConversionDataListener?: boolean;
onDeepLinkListener?: boolean;
timeToWaitForATTUserAuthorization?: number; // iOS only
manualStart?: boolean
}

export interface InAppPurchase {
Expand Down Expand Up @@ -157,6 +158,8 @@ declare module "react-native-appsflyer" {
setCollectIMEI(isCollect: boolean, successC?: SuccessCB): void
setCollectAndroidID(isCollect: boolean, successC?: SuccessCB): void
setDisableNetworkData(disable: boolean): void
startSdk(): void
performOnDeepLinking(): void
};

export default appsFlyer;
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ appsFlyer.setDisableNetworkData = (disable) => {
return RNAppsFlyer.setDisableNetworkData(disable);
};

appsFlyer.startSdk = () => {
return RNAppsFlyer.startSdk();
};

appsFlyer.performOnDeepLinking = () => {
return RNAppsFlyer.performOnDeepLinking();
};

function AFParseJSONException(_message, _data) {
this.message = _message;
this.data = _data;
Expand Down

0 comments on commit f4e4d0c

Please sign in to comment.