reactnative-plugin-appice 1.7.15 → 1.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +9 -7
- package/example/App.js +14 -11
- package/example/PageA.tsx +16 -0
- package/example/ancilliary.js +15 -5
- package/example/android/build.gradle +3 -3
- package/example/android/gradlew +0 -0
- package/example/package.json +1 -1
- package/example/usePageTracking.ts +88 -0
- package/ios/AppIceReactPlugin.xcworkspace/xcuserdata/artherajesh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -10,10 +10,9 @@
|
|
|
10
10
|
// original location:
|
|
11
11
|
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
|
|
12
12
|
|
|
13
|
-
def DEFAULT_COMPILE_SDK_VERSION =
|
|
14
|
-
def
|
|
15
|
-
def
|
|
16
|
-
def DEFAULT_TARGET_SDK_VERSION = 33
|
|
13
|
+
def DEFAULT_COMPILE_SDK_VERSION = 34
|
|
14
|
+
def DEFAULT_MIN_SDK_VERSION = 21
|
|
15
|
+
def DEFAULT_TARGET_SDK_VERSION = 34
|
|
17
16
|
|
|
18
17
|
def safeExtGet(prop, fallback) {
|
|
19
18
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
@@ -41,12 +40,12 @@ apply plugin: 'com.android.library'
|
|
|
41
40
|
|
|
42
41
|
android {
|
|
43
42
|
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
|
|
44
|
-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
|
|
45
43
|
defaultConfig {
|
|
46
44
|
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
|
|
47
45
|
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
|
|
48
46
|
versionCode 2
|
|
49
47
|
versionName "2.0"
|
|
48
|
+
multiDexEnabled true
|
|
50
49
|
}
|
|
51
50
|
lintOptions {
|
|
52
51
|
abortOnError false
|
|
@@ -103,7 +102,7 @@ dependencies {
|
|
|
103
102
|
implementation "com.android.installreferrer:installreferrer:2.2"
|
|
104
103
|
|
|
105
104
|
//firebase
|
|
106
|
-
implementation "com.google.firebase:firebase-messaging:
|
|
105
|
+
implementation "com.google.firebase:firebase-messaging:24.0.0"
|
|
107
106
|
|
|
108
107
|
// maps
|
|
109
108
|
implementation "com.google.android.gms:play-services-maps:18.0.0"
|
|
@@ -114,11 +113,14 @@ dependencies {
|
|
|
114
113
|
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.3.1"
|
|
115
114
|
|
|
116
115
|
//appice
|
|
117
|
-
implementation 'appice.io.android:sdk:2.5.
|
|
116
|
+
implementation 'appice.io.android:sdk:2.5.81'
|
|
118
117
|
|
|
119
118
|
//glide
|
|
120
119
|
implementation "com.github.bumptech.glide:glide:4.11.0"
|
|
121
120
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
|
121
|
+
|
|
122
|
+
// multidex
|
|
123
|
+
implementation 'com.android.support:multidex:1.0.3'
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
def configureReactNativePom(def pom) {
|
package/example/App.js
CHANGED
|
@@ -21,6 +21,9 @@ import { getInboxMessages, getMessageCounts, setUser, updatedInboxMessage } from
|
|
|
21
21
|
import { handleUrl,receiveDeepLink } from './offerIdhandler';
|
|
22
22
|
const AppICE = require('reactnative-plugin-appice');
|
|
23
23
|
const HelloWorldApp = () => {
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
24
27
|
const certs: never[] = [];
|
|
25
28
|
if (AppICE) {
|
|
26
29
|
console.log('AppICE is available');
|
|
@@ -37,17 +40,16 @@ const HelloWorldApp = () => {
|
|
|
37
40
|
certs
|
|
38
41
|
);
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
addAppICEAPIListeners();
|
|
44
|
+
|
|
45
|
+
AppState.addEventListener('change', (nextAppState) => {
|
|
46
|
+
if (nextAppState === 'active') {
|
|
47
|
+
AppICE.registerLifeCycle()
|
|
48
|
+
|
|
49
|
+
AppICE.isDeviceReady(true);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
|
|
@@ -76,6 +78,7 @@ const HelloWorldApp = () => {
|
|
|
76
78
|
<Button onPress={synchronizeInbox} title="synchronizeInbox" color="#841584" />
|
|
77
79
|
<Button onPress={getUserDetails} title="getUserDetails" color="#841584" />
|
|
78
80
|
<Button onPress={getUserData} title="getUserData" color="#841584" />
|
|
81
|
+
|
|
79
82
|
</View>
|
|
80
83
|
);
|
|
81
84
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, Button } from 'react-native';
|
|
3
|
+
import { usePageTracking } from './usePageTracking';
|
|
4
|
+
|
|
5
|
+
const PageA = ({ navigation }: { navigation: any }) => {
|
|
6
|
+
usePageTracking('A', navigation);
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<View>
|
|
10
|
+
<Text>Page A</Text>
|
|
11
|
+
<Button title="Go to Page B" onPress={() => navigation.navigate('PageB')} />
|
|
12
|
+
</View>
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default PageA;
|
package/example/ancilliary.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable prettier/prettier */
|
|
2
2
|
const AppICE = require('reactnative-plugin-appice');
|
|
3
3
|
import { URL } from 'react-native-url-polyfill';
|
|
4
|
-
import { getInboxMessageForId , synchronizeInbox} from './App';
|
|
5
4
|
|
|
6
5
|
/* eslint-disable prettier/prettier */
|
|
7
6
|
/**
|
|
@@ -415,13 +414,24 @@ const setUser = (profile) => {
|
|
|
415
414
|
* @param {string} useId user id
|
|
416
415
|
* @param {object} callback return the response
|
|
417
416
|
*/
|
|
418
|
-
const getOfferDataForDeeplink = (dl,
|
|
417
|
+
const getOfferDataForDeeplink = (dl,timeout, callback) =>{
|
|
419
418
|
const mid = extractMidFromDeepLink(dl);
|
|
420
419
|
const offerid = extractOfferIdFromDeepLink(dl);
|
|
421
420
|
if(mid != null){
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
421
|
+
const userId = null;
|
|
422
|
+
AppICE.getUserId((userIds) => {
|
|
423
|
+
userId = JSON.parse(userIds)[0];
|
|
424
|
+
console.log('getUserId parse:', userId);
|
|
425
|
+
if (!userId) {
|
|
426
|
+
userId = userIds[0];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
AppICE.synchronizeInbox(timeout, (success) => {
|
|
430
|
+
if(success){
|
|
431
|
+
AppICE.getInboxMessageForId(mid, userId, (inboxMessage) => {
|
|
432
|
+
callback(inboxMessage)
|
|
433
|
+
});
|
|
434
|
+
}
|
|
425
435
|
});
|
|
426
436
|
}
|
|
427
437
|
}
|
|
@@ -4,10 +4,10 @@ import org.apache.tools.ant.taskdefs.condition.Os
|
|
|
4
4
|
|
|
5
5
|
buildscript {
|
|
6
6
|
ext {
|
|
7
|
-
buildToolsVersion = "
|
|
7
|
+
buildToolsVersion = "34.0.0"
|
|
8
8
|
minSdkVersion = 21
|
|
9
|
-
compileSdkVersion =
|
|
10
|
-
targetSdkVersion =
|
|
9
|
+
compileSdkVersion = 34
|
|
10
|
+
targetSdkVersion = 34
|
|
11
11
|
|
|
12
12
|
if (System.properties['os.arch'] == "aarch64") {
|
|
13
13
|
// For M1 Users we need to use the NDK 24 which added support for aarch64
|
package/example/android/gradlew
CHANGED
|
File without changes
|
package/example/package.json
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { AppState, AppStateStatus } from 'react-native';
|
|
3
|
+
import AppICE from 'reactnative-plugin-appice';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* usePageTracking
|
|
7
|
+
* PageView Event - The PageView event is used to Identify the moment a user views or lands
|
|
8
|
+
on a particular page or screen in your application.
|
|
9
|
+
* PageDuration Event - The PageDuration event measures the amount of time a user spends
|
|
10
|
+
on a particular page or screen
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const usePageTracking = (pageName: string, navigation: any) => {
|
|
15
|
+
const [startTime, setStartTime] = useState<number | null>(null);
|
|
16
|
+
const appState = useRef<AppStateStatus>(AppState.currentState);
|
|
17
|
+
const isPageFocused = useRef(false); // Track if the page is currently focused
|
|
18
|
+
const isForeground = useRef(true); // Track if the app is in the foreground
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
// Function to trigger PageView event
|
|
22
|
+
const triggerPageView = () => {
|
|
23
|
+
if (!isPageFocused.current) { // Ensure the PageView is triggered only once
|
|
24
|
+
setStartTime(Date.now());
|
|
25
|
+
const dataObj = { view: pageName };
|
|
26
|
+
console.log(`PageView event triggered for page: ${pageName}`);
|
|
27
|
+
AppICE.tagEvent('PageView', dataObj);
|
|
28
|
+
isPageFocused.current = true;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Function to trigger PageDuration event
|
|
33
|
+
const triggerPageDuration = () => {
|
|
34
|
+
if (isPageFocused.current && startTime) {
|
|
35
|
+
const endTime = Date.now();
|
|
36
|
+
const totalSeconds = Math.floor((endTime - startTime) / 1000);
|
|
37
|
+
const dataObj = { name: pageName, duration: totalSeconds };
|
|
38
|
+
console.log(`PageDuration event triggered for page: ${pageName}, duration: ${totalSeconds}s`);
|
|
39
|
+
AppICE.tagEvent('PageDuration', dataObj);
|
|
40
|
+
setStartTime(null); // Reset the start time
|
|
41
|
+
isPageFocused.current = false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Handle focus and blur events
|
|
46
|
+
const handleFocus = () => {
|
|
47
|
+
console.log(`Page ${pageName} focused`);
|
|
48
|
+
if (isForeground.current) {
|
|
49
|
+
triggerPageView(); // Trigger PageView only when the app is in the foreground
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleBlur = () => {
|
|
54
|
+
console.log(`Page ${pageName} lost focus`);
|
|
55
|
+
triggerPageDuration(); // Trigger PageDuration when leaving the page
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const unsubscribeFocus = navigation.addListener('focus', handleFocus);
|
|
59
|
+
const unsubscribeBlur = navigation.addListener('blur', handleBlur);
|
|
60
|
+
|
|
61
|
+
// Handle app state changes (background/foreground)
|
|
62
|
+
const handleAppStateChange = (nextAppState: AppStateStatus) => {
|
|
63
|
+
console.log(`AppState changed from ${appState.current} to ${nextAppState}`);
|
|
64
|
+
if (appState.current.match(/active|inactive/) && nextAppState === 'background') {
|
|
65
|
+
triggerPageDuration(); // App went to background
|
|
66
|
+
isForeground.current = false;
|
|
67
|
+
} else if (appState.current === 'background' && nextAppState === 'active') {
|
|
68
|
+
isForeground.current = true;
|
|
69
|
+
if (isPageFocused.current) {
|
|
70
|
+
console.log(`Re-triggering PageView for page: ${pageName} after returning from background`);
|
|
71
|
+
triggerPageView(); // Re-trigger PageView when coming back to foreground
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
appState.current = nextAppState; // Update app state
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const appStateListener = AppState.addEventListener('change', handleAppStateChange);
|
|
78
|
+
|
|
79
|
+
// Cleanup listeners on unmount
|
|
80
|
+
return () => {
|
|
81
|
+
unsubscribeFocus();
|
|
82
|
+
unsubscribeBlur();
|
|
83
|
+
appStateListener.remove();
|
|
84
|
+
triggerPageDuration(); // Trigger duration if unmounted
|
|
85
|
+
};
|
|
86
|
+
}, [navigation, pageName, startTime]);
|
|
87
|
+
|
|
88
|
+
};
|
|
Binary file
|