posthog-react-native 1.1.4 → 2.0.0-alpha8

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.
Files changed (129) hide show
  1. package/README.md +9 -0
  2. package/lib/index.cjs.js +1761 -0
  3. package/lib/index.cjs.js.map +1 -0
  4. package/lib/index.d.ts +211 -0
  5. package/lib/index.esm.js +1725 -0
  6. package/lib/index.esm.js.map +1 -0
  7. package/lib/node_modules/tslib/tslib.es6.d.ts +35 -0
  8. package/lib/posthog-core/src/eventemitter.d.ts +8 -0
  9. package/lib/posthog-core/src/index.d.ts +84 -0
  10. package/lib/posthog-core/src/lz-string.d.ts +8 -0
  11. package/lib/posthog-core/src/types.d.ts +68 -0
  12. package/lib/posthog-core/src/utils.d.ts +13 -0
  13. package/lib/posthog-react-native/index.d.ts +10 -0
  14. package/lib/posthog-react-native/src/PostHogProvider.d.ts +13 -0
  15. package/lib/posthog-react-native/src/PosthogContext.d.ts +5 -0
  16. package/lib/posthog-react-native/src/autocapture.d.ts +3 -0
  17. package/lib/posthog-react-native/src/hooks/useFeatureFlag.d.ts +1 -0
  18. package/lib/posthog-react-native/src/hooks/useFeatureFlags.d.ts +3 -0
  19. package/lib/posthog-react-native/src/hooks/useLifecycleTracker.d.ts +2 -0
  20. package/lib/posthog-react-native/src/hooks/useNavigationTracker.d.ts +5 -0
  21. package/lib/posthog-react-native/src/hooks/usePostHog.d.ts +2 -0
  22. package/lib/posthog-react-native/src/legacy.d.ts +4 -0
  23. package/lib/posthog-react-native/src/optional-imports.d.ts +6 -0
  24. package/lib/posthog-react-native/src/posthog-rn.d.ts +14 -0
  25. package/lib/posthog-react-native/src/storage.d.ts +8 -0
  26. package/lib/posthog-react-native/src/types.d.ts +12 -0
  27. package/package.json +35 -51
  28. package/RNPostHog.podspec +0 -21
  29. package/android/build.gradle +0 -46
  30. package/android/src/main/AndroidManifest.xml +0 -1
  31. package/android/src/main/java/com/posthog/reactnative/core/RNPostHogModule.kt +0 -251
  32. package/android/src/main/java/com/posthog/reactnative/core/RNPostHogPackage.kt +0 -44
  33. package/build/cjs/__mocks__/bridge.d.ts +0 -14
  34. package/build/cjs/__mocks__/bridge.js +0 -15
  35. package/build/cjs/__mocks__/bridge.js.map +0 -1
  36. package/build/cjs/__tests__/bridge.spec.d.ts +0 -1
  37. package/build/cjs/__tests__/bridge.spec.js +0 -19
  38. package/build/cjs/__tests__/bridge.spec.js.map +0 -1
  39. package/build/cjs/__tests__/configuration.spec.d.ts +0 -1
  40. package/build/cjs/__tests__/configuration.spec.js +0 -131
  41. package/build/cjs/__tests__/configuration.spec.js.map +0 -1
  42. package/build/cjs/__tests__/index.spec.d.ts +0 -1
  43. package/build/cjs/__tests__/index.spec.js +0 -9
  44. package/build/cjs/__tests__/index.spec.js.map +0 -1
  45. package/build/cjs/__tests__/posthog.spec.d.ts +0 -1
  46. package/build/cjs/__tests__/posthog.spec.js +0 -193
  47. package/build/cjs/__tests__/posthog.spec.js.map +0 -1
  48. package/build/cjs/bridge.d.ts +0 -50
  49. package/build/cjs/bridge.js +0 -9
  50. package/build/cjs/bridge.js.map +0 -1
  51. package/build/cjs/configuration.d.ts +0 -3
  52. package/build/cjs/configuration.js +0 -94
  53. package/build/cjs/configuration.js.map +0 -1
  54. package/build/cjs/index.d.ts +0 -5
  55. package/build/cjs/index.js +0 -6
  56. package/build/cjs/index.js.map +0 -1
  57. package/build/cjs/make-pkg.d.ts +0 -1
  58. package/build/cjs/make-pkg.js +0 -5
  59. package/build/cjs/make-pkg.js.map +0 -1
  60. package/build/cjs/middleware.d.ts +0 -41
  61. package/build/cjs/middleware.js +0 -114
  62. package/build/cjs/middleware.js.map +0 -1
  63. package/build/cjs/posthog.d.ts +0 -228
  64. package/build/cjs/posthog.js +0 -309
  65. package/build/cjs/posthog.js.map +0 -1
  66. package/build/cjs/utils.d.ts +0 -1
  67. package/build/cjs/utils.js +0 -7
  68. package/build/cjs/utils.js.map +0 -1
  69. package/build/cjs/wrapper.d.ts +0 -22
  70. package/build/cjs/wrapper.js +0 -114
  71. package/build/cjs/wrapper.js.map +0 -1
  72. package/build/esm/__mocks__/bridge.d.ts +0 -14
  73. package/build/esm/__mocks__/bridge.js +0 -13
  74. package/build/esm/__mocks__/bridge.js.map +0 -1
  75. package/build/esm/__tests__/bridge.spec.d.ts +0 -1
  76. package/build/esm/__tests__/bridge.spec.js +0 -19
  77. package/build/esm/__tests__/bridge.spec.js.map +0 -1
  78. package/build/esm/__tests__/configuration.spec.d.ts +0 -1
  79. package/build/esm/__tests__/configuration.spec.js +0 -129
  80. package/build/esm/__tests__/configuration.spec.js.map +0 -1
  81. package/build/esm/__tests__/index.spec.d.ts +0 -1
  82. package/build/esm/__tests__/index.spec.js +0 -7
  83. package/build/esm/__tests__/index.spec.js.map +0 -1
  84. package/build/esm/__tests__/posthog.spec.d.ts +0 -1
  85. package/build/esm/__tests__/posthog.spec.js +0 -191
  86. package/build/esm/__tests__/posthog.spec.js.map +0 -1
  87. package/build/esm/bridge.d.ts +0 -50
  88. package/build/esm/bridge.js +0 -7
  89. package/build/esm/bridge.js.map +0 -1
  90. package/build/esm/configuration.d.ts +0 -3
  91. package/build/esm/configuration.js +0 -92
  92. package/build/esm/configuration.js.map +0 -1
  93. package/build/esm/index.d.ts +0 -5
  94. package/build/esm/index.js +0 -4
  95. package/build/esm/index.js.map +0 -1
  96. package/build/esm/make-pkg.d.ts +0 -1
  97. package/build/esm/make-pkg.js +0 -3
  98. package/build/esm/make-pkg.js.map +0 -1
  99. package/build/esm/middleware.d.ts +0 -41
  100. package/build/esm/middleware.js +0 -112
  101. package/build/esm/middleware.js.map +0 -1
  102. package/build/esm/posthog.d.ts +0 -228
  103. package/build/esm/posthog.js +0 -307
  104. package/build/esm/posthog.js.map +0 -1
  105. package/build/esm/utils.d.ts +0 -1
  106. package/build/esm/utils.js +0 -4
  107. package/build/esm/utils.js.map +0 -1
  108. package/build/esm/wrapper.d.ts +0 -22
  109. package/build/esm/wrapper.js +0 -112
  110. package/build/esm/wrapper.js.map +0 -1
  111. package/build/package.json +0 -3
  112. package/ios/RNPostHog/RNPostHog.h +0 -9
  113. package/ios/RNPostHog/RNPostHog.m +0 -128
  114. package/ios/RNPostHog.xcodeproj/project.pbxproj +0 -336
  115. package/ios/RNPostHog.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  116. package/src/__mocks__/bridge.ts +0 -12
  117. package/src/__tests__/bridge.spec.ts +0 -23
  118. package/src/__tests__/configuration.spec.ts +0 -79
  119. package/src/__tests__/index.spec.ts +0 -7
  120. package/src/__tests__/posthog.spec.ts +0 -108
  121. package/src/bridge.ts +0 -61
  122. package/src/configuration.ts +0 -61
  123. package/src/index.ts +0 -5
  124. package/src/make-pkg.ts +0 -3
  125. package/src/middleware.ts +0 -128
  126. package/src/modules.d.ts +0 -2
  127. package/src/posthog.ts +0 -305
  128. package/src/utils.ts +0 -3
  129. package/src/wrapper.ts +0 -61
@@ -0,0 +1,14 @@
1
+ import { PostHogCore, PosthogCoreOptions, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty } from '../../posthog-core/src';
2
+ export declare type PostHogOptions = PosthogCoreOptions;
3
+ export declare class PostHog extends PostHogCore {
4
+ static initAsync(): Promise<void>;
5
+ constructor(apiKey: string, options?: PostHogOptions);
6
+ getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
7
+ setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
8
+ fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
9
+ getLibraryId(): string;
10
+ getLibraryVersion(): string;
11
+ getCustomUserAgent(): void;
12
+ getCommonEventProperties(): any;
13
+ screen(name: string, properties?: any): this;
14
+ }
@@ -0,0 +1,8 @@
1
+ export declare const SemiAsyncStorage: {
2
+ getItem: (key: string) => any | null | undefined;
3
+ setItem: (key: string, value: any) => void;
4
+ removeItem: (key: string) => void;
5
+ clear: () => void;
6
+ getAllKeys: () => readonly string[];
7
+ };
8
+ export declare const preloadSemiAsyncStorage: () => Promise<void>;
@@ -0,0 +1,12 @@
1
+ export declare type PostHogAutocaptureNavigationTrackerOptions = {
2
+ routeToName?: (name: string, params: any) => string;
3
+ routeToProperties?: (name: string, params: any) => string;
4
+ };
5
+ export declare type PostHogAutocaptureOptions = {
6
+ captureTouches?: boolean;
7
+ customLabelProp?: string;
8
+ noCaptureProp?: string;
9
+ maxElementsCaptured?: number;
10
+ ignoreLabels?: string[];
11
+ navigation?: PostHogAutocaptureNavigationTrackerOptions;
12
+ };
package/package.json CHANGED
@@ -1,62 +1,46 @@
1
1
  {
2
2
  "name": "posthog-react-native",
3
- "version": "1.1.4",
4
- "description": "The hassle-free way to add PostHog to your React-Native app.",
5
- "license": "MIT",
6
- "main": "build/cjs/index.js",
7
- "module": "build/esm/index.js",
8
- "types": "build/esm/index.d.ts",
3
+ "version": "2.0.0-alpha8",
4
+ "main": "lib/index.cjs.js",
5
+ "module": "lib/index.esm.js",
6
+ "types": "lib/index.d.ts",
9
7
  "files": [
10
- "android",
11
- "ios",
12
- "build",
13
- "src",
14
- "RNPostHog.podspec"
8
+ "lib/"
15
9
  ],
10
+ "dependencies": {},
16
11
  "scripts": {
17
- "build:clean": "rimraf build",
18
- "build:ts": "run-p build:ts:*",
19
- "build:ts:cjs": "tsc --target es5 --outDir build/cjs --module commonjs",
20
- "build:ts:esm": "tsc --target es5 --outDir build/esm --module esnext",
21
- "build:pkg": "ts-node -T src/make-pkg.ts > build/package.json",
22
- "build": "run-s build:{clean,ts,pkg}",
23
- "lint": "tslint -p ../packages",
24
- "test": "jest",
25
- "deploy": "deploy.sh",
26
- "prepublish": "yarn build"
12
+ "test": "jest -c jest.config.js",
13
+ "prepublish": "cd .. && yarn build"
27
14
  },
28
15
  "devDependencies": {
29
- "@types/jest": "^23.3.1",
30
- "babel-core": "^6.26.3",
31
- "babel-jest": "^23.4.2",
32
- "jest": "^23.4.2",
33
- "jest-mock-console": "^0.4.0",
34
- "standard-version": "^4.4.0",
35
- "ts-jest": "^23.1.3",
36
- "ts-node": "^7.0.1",
37
- "tslint": "^5.11.0",
38
- "tslint-config-prettier": "^1.14.0",
39
- "tslint-plugin-prettier": "^2.0.0",
40
- "typedoc": "^0.12.0",
41
- "typedoc-plugin-markdown": "^1.1.13",
42
- "typescript": "^3.0.1"
16
+ "@react-navigation/native": "^5.0.10",
17
+ "@types/react-native": "^0.69.1",
18
+ "expo": "^45.0.6",
19
+ "expo-application": "^4.0.0",
20
+ "expo-device": "^4.0.0",
21
+ "expo-file-system": "^13.0.0",
22
+ "expo-localization": "~11.0.0",
23
+ "expo-network": "^4.2.0",
24
+ "react": "^18.2.0",
25
+ "react-native": "^0.69.1"
43
26
  },
44
- "jest": {
45
- "transform": {
46
- "^.+\\.tsx?$": "ts-jest"
27
+ "peerDependencies": {
28
+ "@react-navigation/native": "^5.0.10",
29
+ "expo-localization": "~11.0.0",
30
+ "expo-network": "^4.0.0",
31
+ "expo-file-system": "^13.0.0",
32
+ "expo-application": "^4.0.0",
33
+ "expo-device": "^4.0.0"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@react-navigation/native": {
37
+ "optional": true
38
+ },
39
+ "expo-localization": {
40
+ "optional": true
47
41
  },
48
- "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(tsx?)$",
49
- "moduleFileExtensions": [
50
- "ts",
51
- "tsx",
52
- "js",
53
- "jsx",
54
- "json",
55
- "node"
56
- ],
57
- "rootDir": "src",
58
- "collectCoverage": true,
59
- "coverageDirectory": "../build/coverage",
60
- "testEnvironment": "node"
42
+ "expo-network": {
43
+ "optional": true
44
+ }
61
45
  }
62
46
  }
package/RNPostHog.podspec DELETED
@@ -1,21 +0,0 @@
1
- require 'json'
2
- package = JSON.parse(File.read('./package.json'))
3
-
4
- Pod::Spec.new do |s|
5
- s.name = 'RNPostHog'
6
- s.version = package['version']
7
- s.summary = package['description']
8
- s.description = "PostHog for iOS"
9
- s.homepage = 'http://posthog.com/'
10
- s.social_media_url = 'https://twitter.com/posthoghq'
11
- s.license = { :type => 'MIT' }
12
- s.author = { 'PostHog' => 'hey@posthog.com' }
13
- s.source = { :git => 'https://github.com/PostHog/posthog-react-native.git', :tag => s.version.to_s }
14
-
15
- s.platform = :ios, '9.0'
16
- s.source_files = 'ios/**/*.{m,h}'
17
- s.static_framework = true
18
-
19
- s.dependency 'PostHog', '~> 1.4.4'
20
- s.dependency 'React'
21
- end
@@ -1,46 +0,0 @@
1
- apply plugin: 'com.android.library'
2
- apply plugin: 'kotlin-android'
3
-
4
- def safeExtGet(prop, fallback) {
5
- return rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
6
- }
7
-
8
- buildscript {
9
- ext.defaultKotlinVersion = '1.3.50'
10
-
11
- repositories {
12
- jcenter()
13
- maven { url 'https://maven.google.com' }
14
- }
15
- dependencies {
16
- classpath 'com.android.tools.build:gradle:3.1.4'
17
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : defaultKotlinVersion}"
18
- }
19
- }
20
-
21
- android {
22
- compileSdkVersion safeExtGet('compileSdkVersion', 26)
23
- buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
24
-
25
- defaultConfig {
26
- minSdkVersion safeExtGet('minSdkVersion', 16)
27
- targetSdkVersion safeExtGet('targetSdkVersion', 26)
28
- versionCode 1
29
- versionName '1.0'
30
- }
31
- }
32
-
33
- repositories {
34
- maven {
35
- url "$rootDir/../node_modules/react-native/android"
36
- name 'React Native (local)'
37
- }
38
- mavenCentral()
39
- }
40
-
41
- dependencies {
42
- api 'com.posthog.android:posthog:1.1.2'
43
-
44
- api 'com.facebook.react:react-native:+'
45
- api "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : defaultKotlinVersion}"
46
- }
@@ -1 +0,0 @@
1
- <manifest package="com.posthog.reactnative.core"/>
@@ -1,251 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2018 Segment, Inc.
5
- *
6
- * Copyright (c) 2020 Hiberly Inc.
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- */
26
-
27
- package com.posthog.reactnative.core
28
-
29
- import android.content.pm.PackageInfo
30
- import android.content.pm.PackageManager
31
- import com.facebook.react.bridge.*
32
- import com.posthog.android.PostHog
33
- import com.posthog.android.Options
34
- import com.posthog.android.Properties
35
- import com.posthog.android.Traits
36
- import com.posthog.android.ValueMap
37
- import com.posthog.android.internal.Utils.getPostHogSharedPreferences
38
- import java.util.concurrent.TimeUnit
39
- import com.facebook.react.bridge.ReadableMap
40
-
41
-
42
-
43
- class RNPostHogModule(context: ReactApplicationContext): ReactContextBaseJavaModule(context) {
44
- override fun getName() = "RNPostHog"
45
-
46
- private val posthog
47
- get() = PostHog.with(reactApplicationContext)
48
-
49
- companion object {
50
- private var singletonJsonConfig: String? = null
51
- private var versionKey = "version"
52
- private var buildKey = "build"
53
- }
54
-
55
- private fun getPackageInfo(): PackageInfo {
56
- val packageManager = reactApplicationContext.packageManager
57
- try {
58
- return packageManager.getPackageInfo(reactApplicationContext.packageName, 0)
59
- } catch (e: PackageManager.NameNotFoundException) {
60
- throw AssertionError("Package not found: " + reactApplicationContext.packageName)
61
- }
62
- }
63
-
64
- /**
65
- * Tracks application lifecycle events - Application Installed, Application Updated and Application Opened
66
- * This is built to exactly mirror the application lifecycle captureing in posthog-android
67
- */
68
- private fun captureApplicationLifecycleEvents(apiKey: String?) {
69
- // Get the current version.
70
- var packageInfo = this.getPackageInfo()
71
- val currentVersion = packageInfo.versionName
72
- val currentBuild = packageInfo.versionCode
73
-
74
- // Get the previous recorded version.
75
- val sharedPreferences = getPostHogSharedPreferences(reactApplicationContext, apiKey)
76
- val previousVersion = sharedPreferences.getString(versionKey, null)
77
- val previousBuild = sharedPreferences.getInt(buildKey, -1)
78
-
79
- // Check and capture Application Installed or Application Updated.
80
- if (previousBuild == -1) {
81
- var installedProperties = Properties()
82
- installedProperties[versionKey] = currentVersion
83
- installedProperties[buildKey] = currentBuild
84
- posthog.capture("Application Installed", installedProperties)
85
- } else if (currentBuild != previousBuild) {
86
- var updatedProperties = Properties()
87
- updatedProperties[versionKey] = currentVersion
88
- updatedProperties[buildKey] = currentBuild
89
- updatedProperties["previous_$versionKey"] = previousVersion
90
- updatedProperties["previous_$buildKey"] = previousBuild
91
- posthog.capture("Application Updated", updatedProperties)
92
- }
93
-
94
- // Capture Application Opened.
95
- var appOpenedProperties = Properties()
96
- appOpenedProperties[versionKey] = currentVersion
97
- appOpenedProperties[buildKey] = currentBuild
98
- posthog.capture("Application Opened", appOpenedProperties)
99
-
100
- // Update the recorded version.
101
- val editor = sharedPreferences.edit()
102
- editor.putString(versionKey, currentVersion)
103
- editor.putInt(buildKey, currentBuild)
104
- editor.apply()
105
- }
106
-
107
- @ReactMethod
108
- fun setup(options: ReadableMap, promise: Promise) {
109
- val json = options.getString("json")
110
- val apiKey = options.getString("apiKey")
111
-
112
- if(singletonJsonConfig != null) {
113
- if(json == singletonJsonConfig) {
114
- return promise.resolve(null)
115
- }
116
- else {
117
- if (BuildConfig.DEBUG) {
118
- return promise.resolve(null)
119
- }
120
- else {
121
- return promise.reject("E_POSTHOG_RECONFIGURED", "PostHog Client was allocated multiple times, please check your environment.")
122
- }
123
- }
124
- }
125
-
126
- val builder = PostHog
127
- .Builder(reactApplicationContext, apiKey, options.getString("host"))
128
-
129
- if (options.hasKey("context")) {
130
- builder.defaultOptions(optionsFrom(options.getMap("context")))
131
- }
132
-
133
- if(options.getBoolean("recordScreenViews")) {
134
- builder.recordScreenViews()
135
- }
136
-
137
- if(options.getBoolean("captureDeepLinks")) {
138
- builder.captureDeepLinks()
139
- }
140
-
141
- if(options.hasKey("android")) {
142
- val androidMap = options.getMap("android")
143
- if (androidMap != null && androidMap.hasKey("collectDeviceId")) {
144
- builder.collectDeviceId(androidMap.getBoolean("collectDeviceId"))
145
- }
146
- }
147
-
148
- if(options.hasKey("flushInterval")) {
149
- builder.flushInterval(
150
- options.getInt("flushInterval").toLong(),
151
- TimeUnit.SECONDS
152
- )
153
- }
154
-
155
- if(options.hasKey("flushAt")) {
156
- builder.flushQueueSize(options.getInt("flushAt"))
157
- }
158
-
159
- if(options.getBoolean("debug")) {
160
- builder.logLevel(PostHog.LogLevel.VERBOSE)
161
- }
162
-
163
- if(options.getBoolean("captureApplicationLifecycleEvents")) {
164
- builder.captureApplicationLifecycleEvents()
165
- }
166
-
167
- try {
168
- PostHog.setSingletonInstance(builder.build())
169
- } catch(e2: IllegalStateException) {
170
- // pass if the error is due to calling setSingletonInstance multiple times
171
-
172
- // if you created singleton in native code already,
173
- // you need to promise.resolve for RN to properly operate
174
- } catch(e: Exception) {
175
- return promise.reject("E_POSTHOG_ERROR", e)
176
- }
177
-
178
- if(options.getBoolean("captureApplicationLifecycleEvents")) {
179
- this.captureApplicationLifecycleEvents(apiKey)
180
- }
181
-
182
- singletonJsonConfig = json
183
- promise.resolve(null)
184
- }
185
-
186
- @ReactMethod
187
- fun capture(event: String, properties: ReadableMap?) =
188
- posthog.capture(
189
- event,
190
- Properties() from properties
191
- )
192
-
193
- @ReactMethod
194
- fun screen(screen: String?, properties: ReadableMap?) =
195
- posthog.screen(
196
- screen,
197
- Properties() from properties
198
- )
199
-
200
- @ReactMethod
201
- fun identify(distinctId: String?, properties: ReadableMap?) =
202
- posthog.identify(
203
- distinctId,
204
- Properties() from properties,
205
- null
206
- )
207
-
208
- @ReactMethod
209
- fun alias(alias: String) =
210
- posthog.alias(
211
- alias
212
- )
213
-
214
- @ReactMethod
215
- fun reset() =
216
- posthog.reset()
217
-
218
- @ReactMethod()
219
- fun flush() =
220
- posthog.flush()
221
-
222
- @ReactMethod
223
- fun enable() =
224
- posthog.optOut(false)
225
-
226
- @ReactMethod
227
- fun disable() =
228
- posthog.optOut(true)
229
-
230
- @ReactMethod
231
- fun getAnonymousId(promise: Promise) =
232
- promise.resolve(posthog.getAnonymousId())
233
- }
234
-
235
- private fun optionsFrom(context: ReadableMap?): Options {
236
- var options = Options()
237
-
238
- context?.toHashMap()?.forEach { (key, value) ->
239
- options.putContext(key, value)
240
- }
241
-
242
- return options
243
- }
244
-
245
- private infix fun<T: ValueMap> T.from(source: ReadableMap?): T {
246
- if (source != null) {
247
- putAll(source.toHashMap())
248
- }
249
-
250
- return this
251
- }
@@ -1,44 +0,0 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2018 Segment, Inc.
5
- *
6
- * Copyright (c) 2020 Hiberly Inc.
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- */
26
-
27
- package com.posthog.reactnative.core
28
-
29
- import android.view.View
30
- import com.facebook.react.ReactPackage
31
- import com.facebook.react.bridge.NativeModule
32
- import com.facebook.react.bridge.ReactApplicationContext
33
- import com.facebook.react.uimanager.ReactShadowNode
34
- import com.facebook.react.uimanager.ViewManager
35
-
36
- class RNPostHogPackage : ReactPackage {
37
- override fun createViewManagers(context: ReactApplicationContext): List<ViewManager<View, ReactShadowNode<*>>> {
38
- return emptyList()
39
- }
40
-
41
- override fun createNativeModules(context: ReactApplicationContext): List<NativeModule> {
42
- return listOf(RNPostHogModule(context))
43
- }
44
- }
@@ -1,14 +0,0 @@
1
- /// <reference types="jest" />
2
- declare const _default: {
3
- alias: jest.Mock<any, any>;
4
- capture: jest.Mock<any, any>;
5
- disable: jest.Mock<any, any>;
6
- enable: jest.Mock<any, any>;
7
- flush: jest.Mock<any, any>;
8
- getAnonymousId: jest.Mock<any, any>;
9
- identify: jest.Mock<any, any>;
10
- reset: jest.Mock<any, any>;
11
- screen: jest.Mock<any, any>;
12
- setup: jest.Mock<any, any>;
13
- };
14
- export default _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- alias: jest.fn(),
5
- capture: jest.fn(),
6
- disable: jest.fn(),
7
- enable: jest.fn(),
8
- flush: jest.fn(),
9
- getAnonymousId: jest.fn(),
10
- identify: jest.fn(),
11
- reset: jest.fn(),
12
- screen: jest.fn(),
13
- setup: jest.fn()
14
- };
15
- //# sourceMappingURL=bridge.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../src/__mocks__/bridge.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACd,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,cAAc,EAAE,IAAI,CAAC,EAAE,EAAE;IACzB,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;IACnB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;CAChB,CAAA"}
@@ -1 +0,0 @@
1
- declare const forceRequire: () => typeof import("../bridge");
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var forceRequire = function () {
3
- jest.resetModules();
4
- return require.requireActual('../bridge');
5
- };
6
- it('should throw an error if the core native module is not linked', function () {
7
- jest.setMock('react-native', {
8
- NativeModules: {}
9
- });
10
- expect(forceRequire).toThrow(/Failed to load PostHog native module./);
11
- });
12
- it('should export the core native module', function () {
13
- var RNPostHog = {};
14
- jest.setMock('react-native', {
15
- NativeModules: { RNPostHog: RNPostHog }
16
- });
17
- expect(forceRequire().default).toBe(RNPostHog);
18
- });
19
- //# sourceMappingURL=bridge.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bridge.spec.js","sourceRoot":"","sources":["../../../src/__tests__/bridge.spec.ts"],"names":[],"mappings":";AAAA,IAAM,YAAY,GAAG;IACpB,IAAI,CAAC,YAAY,EAAE,CAAA;IAEnB,OAAO,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,EAAE,CAAC,+DAA+D,EAAE;IACnE,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;QAC5B,aAAa,EAAE,EAAE;KACjB,CAAC,CAAA;IAEF,MAAM,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAA;AACtE,CAAC,CAAC,CAAA;AAEF,EAAE,CAAC,sCAAsC,EAAE;IAC1C,IAAM,SAAS,GAAG,EAAE,CAAA;IAEpB,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;QAC5B,aAAa,EAAE,EAAE,SAAS,WAAA,EAAE;KAC5B,CAAC,CAAA;IAEF,MAAM,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;AAC/C,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};