@kissmyappss/react-native 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +178 -2
- package/lib/client.d.ts +127 -0
- package/lib/client.js +511 -0
- package/lib/device.d.ts +2 -0
- package/lib/device.js +59 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +89 -0
- package/lib/navigation.d.ts +10 -0
- package/lib/navigation.js +18 -0
- package/package.json +34 -4
- package/src/client.ts +598 -0
- package/src/device.ts +59 -0
- package/src/index.ts +88 -0
- package/src/navigation.ts +18 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// KissMyApps analytics for React Native: sessions, installs, opens, screens and your own
|
|
3
|
+
// events, sent to your KissMyApps project. Pure JavaScript, so there is nothing to link.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.KissMyApps = exports.SDK_VERSION = exports.KmaClient = void 0;
|
|
6
|
+
exports.trackNavigation = trackNavigation;
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const client_1 = require("./client");
|
|
9
|
+
const device_1 = require("./device");
|
|
10
|
+
const navigation_1 = require("./navigation");
|
|
11
|
+
var client_2 = require("./client");
|
|
12
|
+
Object.defineProperty(exports, "KmaClient", { enumerable: true, get: function () { return client_2.KmaClient; } });
|
|
13
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return client_2.SDK_VERSION; } });
|
|
14
|
+
let client = null;
|
|
15
|
+
// Calls made before init run once it is called.
|
|
16
|
+
const early = [];
|
|
17
|
+
function call(run) {
|
|
18
|
+
if (client)
|
|
19
|
+
run(client);
|
|
20
|
+
else if (early.length < 100)
|
|
21
|
+
early.push(run);
|
|
22
|
+
}
|
|
23
|
+
exports.KissMyApps = {
|
|
24
|
+
/** Starts the SDK once, as early as possible, with the project's client key. */
|
|
25
|
+
init(options) {
|
|
26
|
+
var _a;
|
|
27
|
+
if (client)
|
|
28
|
+
return client;
|
|
29
|
+
const started = new client_1.KmaClient(options, {
|
|
30
|
+
storage: (_a = options.storage) !== null && _a !== void 0 ? _a : null,
|
|
31
|
+
device: device_1.deviceInfo,
|
|
32
|
+
fetch: (url, init) => fetch(url, init),
|
|
33
|
+
sdk: `kma-react-native/${client_1.SDK_VERSION}`,
|
|
34
|
+
});
|
|
35
|
+
client = started;
|
|
36
|
+
if (react_native_1.AppState.currentState !== 'background')
|
|
37
|
+
started.foreground();
|
|
38
|
+
react_native_1.AppState.addEventListener('change', (state) => {
|
|
39
|
+
if (state === 'active')
|
|
40
|
+
started.foreground();
|
|
41
|
+
else if (state === 'background')
|
|
42
|
+
started.background();
|
|
43
|
+
});
|
|
44
|
+
for (const run of early.splice(0))
|
|
45
|
+
run(started);
|
|
46
|
+
return started;
|
|
47
|
+
},
|
|
48
|
+
track(name, properties) {
|
|
49
|
+
call((kma) => kma.track(name, properties));
|
|
50
|
+
},
|
|
51
|
+
screen(name, properties) {
|
|
52
|
+
call((kma) => kma.screen(name, properties));
|
|
53
|
+
},
|
|
54
|
+
identify(userId, traits) {
|
|
55
|
+
call((kma) => kma.identify(userId, traits));
|
|
56
|
+
},
|
|
57
|
+
setTraits(traits) {
|
|
58
|
+
call((kma) => kma.setTraits(traits));
|
|
59
|
+
},
|
|
60
|
+
reset() {
|
|
61
|
+
call((kma) => kma.reset());
|
|
62
|
+
},
|
|
63
|
+
flush() {
|
|
64
|
+
var _a;
|
|
65
|
+
return (_a = client === null || client === void 0 ? void 0 : client.flush()) !== null && _a !== void 0 ? _a : Promise.resolve();
|
|
66
|
+
},
|
|
67
|
+
optOut() {
|
|
68
|
+
call((kma) => kma.optOut());
|
|
69
|
+
},
|
|
70
|
+
optIn() {
|
|
71
|
+
call((kma) => kma.optIn());
|
|
72
|
+
},
|
|
73
|
+
getAnonymousId() {
|
|
74
|
+
var _a;
|
|
75
|
+
return (_a = client === null || client === void 0 ? void 0 : client.getAnonymousId()) !== null && _a !== void 0 ? _a : null;
|
|
76
|
+
},
|
|
77
|
+
getSessionId() {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = client === null || client === void 0 ? void 0 : client.getSessionId()) !== null && _a !== void 0 ? _a : null;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Screen views from React Navigation:
|
|
84
|
+
* `<NavigationContainer ref={ref} {...trackNavigation(ref)}>`.
|
|
85
|
+
*/
|
|
86
|
+
function trackNavigation(ref) {
|
|
87
|
+
return (0, navigation_1.navigationTracker)(ref, (name) => exports.KissMyApps.screen(name));
|
|
88
|
+
}
|
|
89
|
+
exports.default = exports.KissMyApps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface NavigationRefLike {
|
|
2
|
+
getCurrentRoute(): {
|
|
3
|
+
name: string;
|
|
4
|
+
} | undefined;
|
|
5
|
+
}
|
|
6
|
+
/** Handlers for NavigationContainer's onReady and onStateChange that report each new screen. */
|
|
7
|
+
export declare function navigationTracker(ref: NavigationRefLike, onScreen: (name: string) => void): {
|
|
8
|
+
onReady: () => void;
|
|
9
|
+
onStateChange: () => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Screen views from React Navigation, without depending on it: anything with
|
|
3
|
+
// getCurrentRoute(), such as the ref from createNavigationContainerRef(), works.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.navigationTracker = navigationTracker;
|
|
6
|
+
/** Handlers for NavigationContainer's onReady and onStateChange that report each new screen. */
|
|
7
|
+
function navigationTracker(ref, onScreen) {
|
|
8
|
+
let last;
|
|
9
|
+
const report = () => {
|
|
10
|
+
var _a;
|
|
11
|
+
const name = (_a = ref.getCurrentRoute()) === null || _a === void 0 ? void 0 : _a.name;
|
|
12
|
+
if (!name || name === last)
|
|
13
|
+
return;
|
|
14
|
+
last = name;
|
|
15
|
+
onScreen(name);
|
|
16
|
+
};
|
|
17
|
+
return { onReady: report, onStateChange: report };
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kissmyappss/react-native",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "KissMyApps analytics for React Native apps: sessions, installs, screens and events.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://kissmyapps.dev",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"react-native": "src/index.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"src",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json",
|
|
18
|
+
"prepack": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react-native": ">=0.70"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.6.0"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"analytics",
|
|
28
|
+
"react-native",
|
|
29
|
+
"expo",
|
|
30
|
+
"mobile-analytics",
|
|
31
|
+
"kissmyapps"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
}
|
|
36
|
+
}
|