@openpanel/react-native 1.0.4 → 1.0.5
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/README.md +115 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -3
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# React Native
|
|
2
|
+
|
|
3
|
+
> 📖 **Full documentation:** [https://openpanel.dev/docs/sdks/react-native](https://openpanel.dev/docs/sdks/react-native)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Looking for a step-by-step tutorial? Check out the [React Native analytics guide](https://openpanel.dev/guides/react-native-analytics).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
### Install dependencies
|
|
12
|
+
|
|
13
|
+
We're dependent on `expo-application` for `buildNumber`, `versionNumber` (and `referrer` on android) and `expo-constants` to get the `user-agent`.
|
|
14
|
+
|
|
15
|
+
```npm
|
|
16
|
+
npm install @openpanel/react-native
|
|
17
|
+
npx expo install expo-application expo-constants
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Initialize
|
|
21
|
+
|
|
22
|
+
On native we use a clientSecret to authenticate the app.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const op = new Openpanel({
|
|
26
|
+
clientId: '{YOUR_CLIENT_ID}',
|
|
27
|
+
clientSecret: '{YOUR_CLIENT_SECRET}',
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### Options
|
|
32
|
+
|
|
33
|
+
##### Common options
|
|
34
|
+
|
|
35
|
+
- `apiUrl` - The url of the openpanel API or your self-hosted instance
|
|
36
|
+
- `clientId` - The client id of your application
|
|
37
|
+
- `clientSecret` - The client secret of your application (**only required for server-side events**)
|
|
38
|
+
- `filter` - A function that will be called before sending an event. If it returns false, the event will not be sent
|
|
39
|
+
- `disabled` - If true, the library will not send any events
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Track event
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
op.track('my_event', { foo: 'bar' });
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Navigation / Screen views
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
#### expo-router
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { usePathname, useSegments } from 'expo-router';
|
|
56
|
+
|
|
57
|
+
const op = new Openpanel({ /* ... */ })
|
|
58
|
+
|
|
59
|
+
function RootLayout() {
|
|
60
|
+
// ...
|
|
61
|
+
const pathname = usePathname()
|
|
62
|
+
// Segments is optional but can be nice to have if you
|
|
63
|
+
// want to group routes together
|
|
64
|
+
// pathname = /posts/123
|
|
65
|
+
// segements = ['posts', '[id]']
|
|
66
|
+
const segments = useSegments()
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
// Simple
|
|
70
|
+
op.screenView(pathname)
|
|
71
|
+
|
|
72
|
+
// With extra data
|
|
73
|
+
op.screenView(pathname, {
|
|
74
|
+
// segments is optional but nice to have
|
|
75
|
+
segments: segments.join('/'),
|
|
76
|
+
// other optional data you want to send with the screen view
|
|
77
|
+
})
|
|
78
|
+
}, [pathname,segments])
|
|
79
|
+
// ...
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
#### react-navigation (simple)
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
import { createNavigationContainerRef } from '@react-navigation/native'
|
|
88
|
+
import { Openpanel } from '@openpanel/react-native'
|
|
89
|
+
|
|
90
|
+
const op = new Openpanel({ /* ... */ })
|
|
91
|
+
const navigationRef = createNavigationContainerRef()
|
|
92
|
+
|
|
93
|
+
export function NavigationRoot() {
|
|
94
|
+
const handleNavigationStateChange = () => {
|
|
95
|
+
const current = navigationRef.getCurrentRoute()
|
|
96
|
+
if (current) {
|
|
97
|
+
op.screenView(current.name, {
|
|
98
|
+
params: current.params,
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<NavigationContainer
|
|
105
|
+
ref={navigationRef}
|
|
106
|
+
onReady={handleNavigationStateChange}
|
|
107
|
+
onStateChange={handleNavigationStateChange}
|
|
108
|
+
>
|
|
109
|
+
<Stack.Navigator />
|
|
110
|
+
</NavigationContainer>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For more information on how to use the SDK, check out the [Javascript SDK](https://openpanel.dev/docs/sdks/javascript#usage).
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var A=Object.create;var c=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var V=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},o=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of v(t))!O.call(e,a)&&a!==r&&c(e,a,{get:()=>t[a],enumerable:!(n=_(t,a))||n.enumerable});return e},s=(e,t,r)=>(o(e,t,"default"),r&&o(r,t,"default")),f=(e,t,r)=>(r=e!=null?A(P(e)):{},o(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>o(c({},"__esModule",{value:!0}),e);var i={};V(i,{OpenPanel:()=>d});module.exports=b(i);var p=f(require("expo-application"),1),m=f(require("expo-constants"),1),l=require("react-native"),u=require("@openpanel/sdk");s(i,require("@openpanel/sdk"),module.exports);var d=class extends u.OpenPanel{constructor(r){super({...r,sdk:"react-native",sdkVersion:"1.0.
|
|
1
|
+
"use strict";var A=Object.create;var c=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var V=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},o=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of v(t))!O.call(e,a)&&a!==r&&c(e,a,{get:()=>t[a],enumerable:!(n=_(t,a))||n.enumerable});return e},s=(e,t,r)=>(o(e,t,"default"),r&&o(r,t,"default")),f=(e,t,r)=>(r=e!=null?A(P(e)):{},o(t||!e||!e.__esModule?c(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>o(c({},"__esModule",{value:!0}),e);var i={};V(i,{OpenPanel:()=>d});module.exports=b(i);var p=f(require("expo-application"),1),m=f(require("expo-constants"),1),l=require("react-native"),u=require("@openpanel/sdk");s(i,require("@openpanel/sdk"),module.exports);var d=class extends u.OpenPanel{constructor(r){super({...r,sdk:"react-native",sdkVersion:"1.0.5"});this.options=r;this.api.addHeader("User-Agent",m.default.getWebViewUserAgentAsync()),l.AppState.addEventListener("change",n=>{n==="active"&&this.setDefaultProperties()}),this.setDefaultProperties()}async setDefaultProperties(){this.setGlobalProperties({__version:p.nativeApplicationVersion,__buildNumber:p.nativeBuildVersion,__referrer:l.Platform.OS==="android"?await p.getInstallReferrerAsync():void 0})}screenView(r,n){super.track("screen_view",{...n,__path:r})}};0&&(module.exports={OpenPanel,...require("@openpanel/sdk")});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"expo-application";import s from"expo-constants";import{AppState as n,Platform as p}from"react-native";import{OpenPanel as a}from"@openpanel/sdk";export*from"@openpanel/sdk";var i=class extends a{constructor(t){super({...t,sdk:"react-native",sdkVersion:"1.0.
|
|
1
|
+
import*as e from"expo-application";import s from"expo-constants";import{AppState as n,Platform as p}from"react-native";import{OpenPanel as a}from"@openpanel/sdk";export*from"@openpanel/sdk";var i=class extends a{constructor(t){super({...t,sdk:"react-native",sdkVersion:"1.0.5"});this.options=t;this.api.addHeader("User-Agent",s.getWebViewUserAgentAsync()),n.addEventListener("change",r=>{r==="active"&&this.setDefaultProperties()}),this.setDefaultProperties()}async setDefaultProperties(){this.setGlobalProperties({__version:e.nativeApplicationVersion,__buildNumber:e.nativeBuildVersion,__referrer:p.OS==="android"?await e.getInstallReferrerAsync():void 0})}screenView(t,r){super.track("screen_view",{...r,__path:t})}};export{i as OpenPanel};
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpanel/react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"module": "./dist/index.js",
|
|
5
|
+
"config": {
|
|
6
|
+
"docPath": "apps/public/content/docs/(tracking)/sdks/react-native.mdx"
|
|
7
|
+
},
|
|
5
8
|
"scripts": {
|
|
6
9
|
"build": "rm -rf dist && tsup",
|
|
7
10
|
"typecheck": "tsc --noEmit"
|
|
8
11
|
},
|
|
9
12
|
"dependencies": {
|
|
10
|
-
"@openpanel/sdk": "1.0.
|
|
13
|
+
"@openpanel/sdk": "1.0.4"
|
|
11
14
|
},
|
|
12
15
|
"devDependencies": {
|
|
13
16
|
"@openpanel/tsconfig": "workspace:*",
|
|
@@ -24,7 +27,7 @@
|
|
|
24
27
|
"type": "module",
|
|
25
28
|
"main": "./dist/index.js",
|
|
26
29
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"files": ["dist"],
|
|
30
|
+
"files": ["dist", "README.md"],
|
|
28
31
|
"exports": {
|
|
29
32
|
".": {
|
|
30
33
|
"import": "./dist/index.js",
|