posthog-react-native 1.1.5 → 2.0.0-alpha7

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 (145) 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 -250
  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/coverage/clover.xml +0 -169
  73. package/build/coverage/coverage-final.json +0 -8
  74. package/build/coverage/lcov-report/base.css +0 -212
  75. package/build/coverage/lcov-report/bridge.ts.html +0 -228
  76. package/build/coverage/lcov-report/configuration.ts.html +0 -228
  77. package/build/coverage/lcov-report/index.html +0 -151
  78. package/build/coverage/lcov-report/index.ts.html +0 -60
  79. package/build/coverage/lcov-report/middleware.ts.html +0 -429
  80. package/build/coverage/lcov-report/posthog.ts.html +0 -960
  81. package/build/coverage/lcov-report/prettify.css +0 -1
  82. package/build/coverage/lcov-report/prettify.js +0 -1
  83. package/build/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  84. package/build/coverage/lcov-report/sorter.js +0 -158
  85. package/build/coverage/lcov-report/utils.ts.html +0 -54
  86. package/build/coverage/lcov-report/wrapper.ts.html +0 -228
  87. package/build/coverage/lcov.info +0 -365
  88. package/build/esm/__mocks__/bridge.d.ts +0 -14
  89. package/build/esm/__mocks__/bridge.js +0 -13
  90. package/build/esm/__mocks__/bridge.js.map +0 -1
  91. package/build/esm/__tests__/bridge.spec.d.ts +0 -1
  92. package/build/esm/__tests__/bridge.spec.js +0 -19
  93. package/build/esm/__tests__/bridge.spec.js.map +0 -1
  94. package/build/esm/__tests__/configuration.spec.d.ts +0 -1
  95. package/build/esm/__tests__/configuration.spec.js +0 -129
  96. package/build/esm/__tests__/configuration.spec.js.map +0 -1
  97. package/build/esm/__tests__/index.spec.d.ts +0 -1
  98. package/build/esm/__tests__/index.spec.js +0 -7
  99. package/build/esm/__tests__/index.spec.js.map +0 -1
  100. package/build/esm/__tests__/posthog.spec.d.ts +0 -1
  101. package/build/esm/__tests__/posthog.spec.js +0 -191
  102. package/build/esm/__tests__/posthog.spec.js.map +0 -1
  103. package/build/esm/bridge.d.ts +0 -50
  104. package/build/esm/bridge.js +0 -7
  105. package/build/esm/bridge.js.map +0 -1
  106. package/build/esm/configuration.d.ts +0 -3
  107. package/build/esm/configuration.js +0 -92
  108. package/build/esm/configuration.js.map +0 -1
  109. package/build/esm/index.d.ts +0 -5
  110. package/build/esm/index.js +0 -4
  111. package/build/esm/index.js.map +0 -1
  112. package/build/esm/make-pkg.d.ts +0 -1
  113. package/build/esm/make-pkg.js +0 -3
  114. package/build/esm/make-pkg.js.map +0 -1
  115. package/build/esm/middleware.d.ts +0 -41
  116. package/build/esm/middleware.js +0 -112
  117. package/build/esm/middleware.js.map +0 -1
  118. package/build/esm/posthog.d.ts +0 -228
  119. package/build/esm/posthog.js +0 -307
  120. package/build/esm/posthog.js.map +0 -1
  121. package/build/esm/utils.d.ts +0 -1
  122. package/build/esm/utils.js +0 -4
  123. package/build/esm/utils.js.map +0 -1
  124. package/build/esm/wrapper.d.ts +0 -22
  125. package/build/esm/wrapper.js +0 -112
  126. package/build/esm/wrapper.js.map +0 -1
  127. package/build/package.json +0 -3
  128. package/ios/RNPostHog/RNPostHog.h +0 -9
  129. package/ios/RNPostHog/RNPostHog.m +0 -128
  130. package/ios/RNPostHog.xcodeproj/project.pbxproj +0 -336
  131. package/ios/RNPostHog.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  132. package/src/__mocks__/bridge.ts +0 -12
  133. package/src/__tests__/bridge.spec.ts +0 -23
  134. package/src/__tests__/configuration.spec.ts +0 -79
  135. package/src/__tests__/index.spec.ts +0 -7
  136. package/src/__tests__/posthog.spec.ts +0 -108
  137. package/src/bridge.ts +0 -61
  138. package/src/configuration.ts +0 -61
  139. package/src/index.ts +0 -5
  140. package/src/make-pkg.ts +0 -3
  141. package/src/middleware.ts +0 -128
  142. package/src/modules.d.ts +0 -2
  143. package/src/posthog.ts +0 -305
  144. package/src/utils.ts +0 -3
  145. 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.5",
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-alpha7",
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,250 +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.ValueMap
36
- import com.posthog.android.internal.Utils.getPostHogSharedPreferences
37
- import java.util.concurrent.TimeUnit
38
- import com.facebook.react.bridge.ReadableMap
39
-
40
-
41
-
42
- class RNPostHogModule(context: ReactApplicationContext): ReactContextBaseJavaModule(context) {
43
- override fun getName() = "RNPostHog"
44
-
45
- private val posthog
46
- get() = PostHog.with(reactApplicationContext)
47
-
48
- companion object {
49
- private var singletonJsonConfig: String? = null
50
- private var versionKey = "version"
51
- private var buildKey = "build"
52
- }
53
-
54
- private fun getPackageInfo(): PackageInfo {
55
- val packageManager = reactApplicationContext.packageManager
56
- try {
57
- return packageManager.getPackageInfo(reactApplicationContext.packageName, 0)
58
- } catch (e: PackageManager.NameNotFoundException) {
59
- throw AssertionError("Package not found: " + reactApplicationContext.packageName)
60
- }
61
- }
62
-
63
- /**
64
- * Tracks application lifecycle events - Application Installed, Application Updated and Application Opened
65
- * This is built to exactly mirror the application lifecycle captureing in posthog-android
66
- */
67
- private fun captureApplicationLifecycleEvents(apiKey: String?) {
68
- // Get the current version.
69
- var packageInfo = this.getPackageInfo()
70
- val currentVersion = packageInfo.versionName
71
- val currentBuild = packageInfo.versionCode
72
-
73
- // Get the previous recorded version.
74
- val sharedPreferences = getPostHogSharedPreferences(reactApplicationContext, apiKey)
75
- val previousVersion = sharedPreferences.getString(versionKey, null)
76
- val previousBuild = sharedPreferences.getInt(buildKey, -1)
77
-
78
- // Check and capture Application Installed or Application Updated.
79
- if (previousBuild == -1) {
80
- var installedProperties = Properties()
81
- installedProperties[versionKey] = currentVersion
82
- installedProperties[buildKey] = currentBuild
83
- posthog.capture("Application Installed", installedProperties)
84
- } else if (currentBuild != previousBuild) {
85
- var updatedProperties = Properties()
86
- updatedProperties[versionKey] = currentVersion
87
- updatedProperties[buildKey] = currentBuild
88
- updatedProperties["previous_$versionKey"] = previousVersion
89
- updatedProperties["previous_$buildKey"] = previousBuild
90
- posthog.capture("Application Updated", updatedProperties)
91
- }
92
-
93
- // Capture Application Opened.
94
- var appOpenedProperties = Properties()
95
- appOpenedProperties[versionKey] = currentVersion
96
- appOpenedProperties[buildKey] = currentBuild
97
- posthog.capture("Application Opened", appOpenedProperties)
98
-
99
- // Update the recorded version.
100
- val editor = sharedPreferences.edit()
101
- editor.putString(versionKey, currentVersion)
102
- editor.putInt(buildKey, currentBuild)
103
- editor.apply()
104
- }
105
-
106
- @ReactMethod
107
- fun setup(options: ReadableMap, promise: Promise) {
108
- val json = options.getString("json")
109
- val apiKey = options.getString("apiKey")
110
-
111
- if(singletonJsonConfig != null) {
112
- if(json == singletonJsonConfig) {
113
- return promise.resolve(null)
114
- }
115
- else {
116
- if (BuildConfig.DEBUG) {
117
- return promise.resolve(null)
118
- }
119
- else {
120
- return promise.reject("E_POSTHOG_RECONFIGURED", "PostHog Client was allocated multiple times, please check your environment.")
121
- }
122
- }
123
- }
124
-
125
- val builder = PostHog
126
- .Builder(reactApplicationContext, apiKey, options.getString("host"))
127
-
128
- if (options.hasKey("context")) {
129
- builder.defaultOptions(optionsFrom(options.getMap("context")))
130
- }
131
-
132
- if(options.getBoolean("recordScreenViews")) {
133
- builder.recordScreenViews()
134
- }
135
-
136
- if(options.getBoolean("captureDeepLinks")) {
137
- builder.captureDeepLinks()
138
- }
139
-
140
- if(options.hasKey("android")) {
141
- val androidMap = options.getMap("android")
142
- if (androidMap != null && androidMap.hasKey("collectDeviceId")) {
143
- builder.collectDeviceId(androidMap.getBoolean("collectDeviceId"))
144
- }
145
- }
146
-
147
- if(options.hasKey("flushInterval")) {
148
- builder.flushInterval(
149
- options.getInt("flushInterval").toLong(),
150
- TimeUnit.SECONDS
151
- )
152
- }
153
-
154
- if(options.hasKey("flushAt")) {
155
- builder.flushQueueSize(options.getInt("flushAt"))
156
- }
157
-
158
- if(options.getBoolean("debug")) {
159
- builder.logLevel(PostHog.LogLevel.VERBOSE)
160
- }
161
-
162
- if(options.getBoolean("captureApplicationLifecycleEvents")) {
163
- builder.captureApplicationLifecycleEvents()
164
- }
165
-
166
- try {
167
- PostHog.setSingletonInstance(builder.build())
168
- } catch(e2: IllegalStateException) {
169
- // pass if the error is due to calling setSingletonInstance multiple times
170
-
171
- // if you created singleton in native code already,
172
- // you need to promise.resolve for RN to properly operate
173
- } catch(e: Exception) {
174
- return promise.reject("E_POSTHOG_ERROR", e)
175
- }
176
-
177
- if(options.getBoolean("captureApplicationLifecycleEvents")) {
178
- this.captureApplicationLifecycleEvents(apiKey)
179
- }
180
-
181
- singletonJsonConfig = json
182
- promise.resolve(null)
183
- }
184
-
185
- @ReactMethod
186
- fun capture(event: String, properties: ReadableMap?) =
187
- posthog.capture(
188
- event,
189
- Properties() from properties
190
- )
191
-
192
- @ReactMethod
193
- fun screen(screen: String?, properties: ReadableMap?) =
194
- posthog.screen(
195
- screen,
196
- Properties() from properties
197
- )
198
-
199
- @ReactMethod
200
- fun identify(distinctId: String?, properties: ReadableMap?) =
201
- posthog.identify(
202
- distinctId,
203
- Properties() from properties,
204
- null
205
- )
206
-
207
- @ReactMethod
208
- fun alias(alias: String) =
209
- posthog.alias(
210
- alias
211
- )
212
-
213
- @ReactMethod
214
- fun reset() =
215
- posthog.reset()
216
-
217
- @ReactMethod()
218
- fun flush() =
219
- posthog.flush()
220
-
221
- @ReactMethod
222
- fun enable() =
223
- posthog.optOut(false)
224
-
225
- @ReactMethod
226
- fun disable() =
227
- posthog.optOut(true)
228
-
229
- @ReactMethod
230
- fun getAnonymousId(promise: Promise) =
231
- promise.resolve(posthog.getAnonymousId())
232
- }
233
-
234
- private fun optionsFrom(context: ReadableMap?): Options {
235
- var options = Options()
236
-
237
- context?.toHashMap()?.forEach { (key, value) ->
238
- options.putContext(key, value)
239
- }
240
-
241
- return options
242
- }
243
-
244
- private infix fun<T: ValueMap> T.from(source: ReadableMap?): T {
245
- if (source != null) {
246
- putAll(source.toHashMap())
247
- }
248
-
249
- return this
250
- }
@@ -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 {};