@attribra/react-native 0.0.0-stage → 2.9.7

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.
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'AurionSignal'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.homepage = package['homepage'] || 'https://signal.irisdigi.cloud'
10
+ s.license = { :type => 'UNLICENSED' }
11
+ s.author = package['author'] || 'Attribra'
12
+ # Match typical RN 0.77 apps (15.1+). StoreKit / SKAN calls are availability-guarded in source.
13
+ s.platforms = { :ios => '15.1' }
14
+ s.source = { :path => '.' }
15
+ s.source_files = 'ios/**/*.{h,m,swift}'
16
+ s.swift_version = '5.0'
17
+ s.frameworks = 'StoreKit', 'AdAttributionKit', 'AppTrackingTransparency', 'AdSupport', 'CryptoKit', 'UIKit'
18
+ s.dependency 'React-Core'
19
+ end
package/INSTALL.md ADDED
@@ -0,0 +1,84 @@
1
+ # Install — React Native / Expo
2
+
3
+ ## From npm (recommended)
4
+
5
+ ```bash
6
+ npm i @attribra/react-native
7
+ cd ios && pod install && cd ..
8
+ # Rebuild Android + iOS so native modules (AurionClipboard, AurionPush, AurionNetwork, …) autolink.
9
+ ```
10
+
11
+ ```tsx
12
+ import { AurionSignal } from '@attribra/react-native'
13
+ ```
14
+
15
+ ## From source / ZIP (dashboard download)
16
+
17
+ 1. Unzip this package into your app, e.g. `src/lib/aurion/`, **or** depend on the local path / published package.
18
+ 2. Optional peers: `@react-native-async-storage/async-storage` (needed to keep offline events across restarts), `@react-native-community/geolocation`. Connectivity for the offline queue is **SDK-native only** via the packaged `AurionNetwork` module (Android `ConnectivityManager` / iOS `NWPathMonitor`). No NetInfo (or other app networking library) is required.
19
+ 3. Create an API key in Attribra → **API Keys** (`asg_…`).
20
+ 4. Add location permissions (Android `ACCESS_FINE_LOCATION` / `ACCESS_COARSE_LOCATION`, iOS `NSLocationWhenInUseUsageDescription`) if you keep the default `collectLocation: true`.
21
+ 5. At app launch:
22
+
23
+ ```tsx
24
+ import { AurionSignal } from '@attribra/react-native'
25
+ // ZIP / copy path: import { AurionSignal } from './lib/aurion'
26
+
27
+ AurionSignal.configure({
28
+ apiKey: 'asg_YOUR_KEY',
29
+ baseUrl: 'https://YOUR_HOST/api', // local: http://YOUR_LAN_IP:8000/api
30
+ onAttribution: (a) => {
31
+ // optional UI — campaign was captured from a deep link
32
+ console.log(a.campaign, a.campaign_id)
33
+ },
34
+ onReattributed: (next, previous) => {
35
+ console.log('Switched', previous.campaign, '→', next.campaign)
36
+ },
37
+ })
38
+ ```
39
+
40
+ 6. Product events: `await AurionSignal.track('sign_in')`
41
+
42
+ **Offline events (SDK 2.9+):** if the device is offline or the request times out / 5xx, `track` / `trackBatch` / `open_app` / `app_install` / `reattributed` are stored locally (up to 100) and sent when the network is back (app foreground, next successful send, or NetInfo if installed). `AurionSignal.flushQueue()` forces a flush; `pendingQueueSize()` shows how many are waiting.
43
+
44
+ Deep links with `campaign_id` / `utm_*` are captured automatically. One `app_install` is sent per device after a short grace window so cold-start App Links are attributed.
45
+
46
+ **Attribra short links** (`https://<host>/l/<app>/<token>`, made in Link builder) need no code beyond `configure`:
47
+ - App already installed: the OS opens the app through the Universal Link / App Link. The SDK sends the URL to `POST /v1/tracking-links/resolve`, which returns the campaign and records the click.
48
+ - Fresh Android install: the link adds the campaign to the Play Store URL as `referrer`. SDK 2.5+ reads it with the bundled `AurionInstallReferrer` native module (autolinked together with the Appnext module) before sending `app_install`. No app code is needed.
49
+ - Fresh iPhone install: the short-link page copies a campaign payload to the clipboard (`aurion_clip=1`), then opens the App Store. On first open the packaged native `AurionClipboard` module reads `UIPasteboard` (no npm clipboard package; iOS may show a paste prompt). If paste is denied or empty, it falls back to `POST /v1/tracking-links/match` (IP + iOS version — best guess). Rebuild the iOS app after updating so the module autolinks.
50
+ - Android where Play cannot answer: same match API fallback.
51
+ - Setup per app (Associated Domains, intent filter) is shown in the dashboard: Integrations, the link icon on the app card.
52
+
53
+ `platform` (android / ios) is set automatically. `user_id` is always the persistent device id (`getDeviceId()`).
54
+
55
+ When an installed device opens a **different** campaign link, the SDK sends a built-in `reattributed` event and future events are credited to that campaign.
56
+
57
+ After install, the SDK also sends `open_app` on cold start and when the app returns from background (`autoOpenApp`, default true).
58
+
59
+ ## Escape hatches (optional)
60
+
61
+ ```tsx
62
+ // Tests / manual paste — not required for production deep links
63
+ AurionSignal.applyAttributionFromUrl(url)
64
+ AurionSignal.applyInstallReferrer(referrer)
65
+ await AurionSignal.flushInstall()
66
+ ```
67
+
68
+ ## SKAdNetwork (iOS, SDK 2.7+)
69
+
70
+ The package includes a native `AurionSkan` module (autolinked with the pod). `configure` starts it on iOS; nothing else to code. It fetches the event-to-number table from the dashboard (SKAN page) and raises the SKAdNetwork conversion value as events are tracked.
71
+
72
+ 1. Run `pod install` after updating.
73
+ 2. Add the App Store ID to the app in the dashboard (Integrations).
74
+ 3. In `ios/<App>/Info.plist` add `NSAdvertisingAttributionReportEndpoint` with `https://YOUR_HOST`.
75
+
76
+ ## Android uninstall / reinstall (SDK 2.8+; GAID-before-install in 2.9.4+)
77
+
78
+ No Firebase setup in the client app. On Android the SDK resolves **GAID first**, then `POST /v1/devices/register` (FCM token when uninstall tracking is enabled), and only then sends `app_install` so reinstall can stitch. It starts a **secondary** Firebase app named `aurion` using options from `GET /v1/apps/firebase-config`. iOS is unchanged (no uninstall/reinstall tracking).
79
+
80
+ - Bind the API key to a Mobile App that has `android_package_name` set so Aurion can auto-provision that package in Attribra’s Firebase project.
81
+ - Rebuild the Android app after updating the package (autolinking pulls `AurionPush` + Firebase Messaging).
82
+ - If the host app already uses Firebase, that stays the default app; Aurion uses the secondary instance only.
83
+ - iOS uninstall probing is deferred (Apple Team / APNs).
84
+ - Server job `devices:probe-android-uninstalls` (every 10 minutes) silent-pushes tokens and emits `uninstall` when FCM reports UNREGISTERED; `reinstall` is emitted when a new install stitches to a prior GAID.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright (c) Attribra / Aurion Signal contributors.
2
+
3
+ All rights reserved.
4
+
5
+ This software is proprietary and confidential. Unauthorized copying, distribution,
6
+ modification, or use of this software, via any medium, is strictly prohibited
7
+ without prior written permission from the copyright holder.
8
+
9
+ UNLICENSED — see package.json "license" field.
package/PUBLISH.md ADDED
@@ -0,0 +1,61 @@
1
+ # Publish `@attribra/react-native` to npm
2
+
3
+ ## Prerequisites
4
+
5
+ 1. Create the npm organization **`attribra`**: https://www.npmjs.com/org/create
6
+ 2. Your user must be an **owner** or have **publish** rights on that org.
7
+ 3. Create a **Granular Access Token** with:
8
+ - Packages: **Read and write**
9
+ - Organization: **attribra** selected
10
+ - **Bypass two-factor authentication** enabled (until your account uses 2FA + OTP login)
11
+
12
+ ```bash
13
+ npm config set //registry.npmjs.org/:_authToken=YOUR_TOKEN
14
+ npm whoami
15
+ ```
16
+
17
+ Do **not** paste tokens into chat, git, or tickets.
18
+
19
+ ## Version
20
+
21
+ Bump `version` in `package.json` and keep `AurionSignal.podspec` `s.version` in sync.
22
+
23
+ ## Dry run
24
+
25
+ ```bash
26
+ cd sdk/react-native
27
+ npm pack --dry-run
28
+ # Expect a small file list (src + android/src + ios + docs). NOT android/build.
29
+ ```
30
+
31
+ ## Publish
32
+
33
+ ```bash
34
+ cd sdk/react-native
35
+ npm publish --access public
36
+ ```
37
+
38
+ First scoped publish must use `--access public`.
39
+
40
+ ## Verify
41
+
42
+ ```bash
43
+ npm view @attribra/react-native version
44
+ ```
45
+
46
+ ## Install in an app
47
+
48
+ ```bash
49
+ npm i @attribra/react-native
50
+ cd ios && pod install && cd ..
51
+ # Rebuild native apps (Android + iOS) so Aurion* native modules autolink.
52
+ ```
53
+
54
+ ```tsx
55
+ import { AurionSignal } from '@attribra/react-native'
56
+
57
+ AurionSignal.configure({
58
+ apiKey: 'asg_YOUR_KEY',
59
+ baseUrl: 'https://signal.irisdigi.cloud/api',
60
+ })
61
+ ```
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # `@attribra/react-native`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Attribra mobile measurement SDK for React Native. Captures deep-link / App Link attribution, sends `app_install` (and Android reinstall via GAID), queues events offline, and supports SKAN + optional Appnext.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @attribra/react-native
9
+ # or: yarn add @attribra/react-native
10
+ ```
11
+
12
+ Then rebuild native projects (autolinking):
13
+
14
+ ```bash
15
+ cd ios && pod install && cd ..
16
+ npx react-native run-android # or your usual Android build
17
+ npx react-native run-ios
18
+ ```
19
+
20
+ ### Optional peers
21
+
22
+ | Package | Why |
23
+ |---------|-----|
24
+ | `@react-native-async-storage/async-storage` | Persist device id, attribution, offline queue across restarts |
25
+ | `@react-native-community/geolocation` | Attach GPS to events when `collectLocation` is true |
26
+
27
+ Connectivity for the offline queue is **built-in** (`AurionNetwork` — no NetInfo required).
28
+
29
+ ## Quick start
30
+
31
+ ```tsx
32
+ import { AurionSignal } from '@attribra/react-native'
33
+
34
+ AurionSignal.configure({
35
+ apiKey: 'asg_YOUR_KEY',
36
+ baseUrl: 'https://signal.irisdigi.cloud/api',
37
+ onAttribution: (a) => console.log('Campaign', a.campaign, a.campaign_id),
38
+ onReattributed: (next, previous) =>
39
+ console.log('Switched', previous.campaign, '→', next.campaign),
40
+ })
41
+
42
+ await AurionSignal.track('sign_in')
43
+ ```
44
+
45
+ Create an API key in the Attribra dashboard (**API Keys**, prefix `asg_`).
46
+
47
+ ## What the SDK does
48
+
49
+ 1. Captures launch / warm deep links and short links (`/l/...`)
50
+ 2. Stores campaign params and attaches them to later `track()` calls
51
+ 3. Sends **one** `app_install` per install after a short grace window
52
+ 4. Uses a persistent `installation_id` as event `user_id` (`getDeviceId()`)
53
+ 5. **Android:** Play Install Referrer; GAID + `/v1/devices/register` before install (reinstall stitch); optional FCM uninstall probing
54
+ 6. **iOS:** clipboard fallback (`aurion_clip` from the short-link page via native `AurionClipboard` / UIPasteboard), then IP+OS match; SKAN when enabled
55
+ 7. Queues events offline and flushes when the network returns
56
+
57
+ ## Config options
58
+
59
+ | Option | Default | Purpose |
60
+ |--------|---------|---------|
61
+ | `autoCaptureDeepLinks` | `true` | Capture launch + `url` events |
62
+ | `deepLinkGraceMs` | `3000` | Wait for late cold-start URL before install |
63
+ | `attributionWindowDays` | `30` | Expire stored campaign (`0` = forever) |
64
+ | `readClipboard` | iOS `true` / Android `false` | Read install clipboard payload on iOS |
65
+ | `collectLocation` | `true` | Request GPS when available |
66
+ | `autoOpenApp` | `true` | Send `open_app` on launch / foreground |
67
+ | `autoInstall` | `true` | Send `app_install` once per device |
68
+ | `onAttribution` | — | Paid campaign captured |
69
+ | `onReattributed` | — | Campaign switch on an installed device |
70
+
71
+ ## Permissions
72
+
73
+ **Android** (if `collectLocation` stays on):
74
+
75
+ ```xml
76
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
77
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
78
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
79
+ <uses-permission android:name="android.permission.INTERNET" />
80
+ ```
81
+
82
+ Also add (for GAID / reinstall):
83
+
84
+ ```gradle
85
+ implementation("com.google.android.gms:play-services-ads-identifier:18.1.0")
86
+ ```
87
+
88
+ (Autolinking already pulls ads-identifier for the packaged Android module when using this package’s `android/` project.)
89
+
90
+ **iOS** `Info.plist`:
91
+
92
+ - `NSLocationWhenInUseUsageDescription` (and often `NSLocationAlwaysAndWhenInUseUsageDescription` if App Store asks)
93
+ - Optional: `NSAdvertisingAttributionReportEndpoint` = your Attribra host for SKAN copies
94
+
95
+ ## baseUrl
96
+
97
+ | Target | Value |
98
+ |--------|--------|
99
+ | Production | `https://signal.irisdigi.cloud/api` |
100
+ | Android emulator | `http://10.0.2.2:8000/api` |
101
+ | iOS simulator | `http://localhost:8000/api` |
102
+ | Physical device | `http://YOUR_LAN_IP:8000/api` |
103
+
104
+ ## App Links / Universal Links
105
+
106
+ Still configured in the **host app** (intent filters, Associated Domains, `assetlinks.json` / AASA). Dashboard → Integrations shows per-app setup.
107
+
108
+ ## More detail
109
+
110
+ See [`INSTALL.md`](./INSTALL.md) in this package.
111
+
112
+ ## License
113
+
114
+ Proprietary — UNLICENSED. See [`LICENSE`](./LICENSE).
@@ -0,0 +1,15 @@
1
+ apply plugin: 'com.android.library'
2
+
3
+ android {
4
+ namespace 'com.aurionsignal.measurement'
5
+ compileSdkVersion rootProject.ext.has('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
6
+ defaultConfig { minSdkVersion 24 }
7
+ }
8
+ dependencies {
9
+ // Use the host app's React Native version (do not pin a newer react-android here).
10
+ implementation "com.facebook.react:react-android"
11
+ implementation 'com.android.installreferrer:installreferrer:2.2'
12
+ implementation platform('com.google.firebase:firebase-bom:33.7.0')
13
+ implementation 'com.google.firebase:firebase-messaging'
14
+ implementation 'com.google.android.gms:play-services-ads-identifier:18.1.0'
15
+ }
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.INTERNET" />
3
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
4
+ </manifest>
@@ -0,0 +1,21 @@
1
+ package com.aurionsignal.measurement;
2
+
3
+ import com.facebook.react.bridge.*;
4
+ import com.aurionsignal.sdk.AppnextMeasurement;
5
+ import org.json.JSONObject;
6
+
7
+ public final class AurionAppnextModule extends ReactContextBaseJavaModule {
8
+ private AppnextMeasurement client;
9
+ public AurionAppnextModule(ReactApplicationContext context) { super(context); }
10
+ @Override public String getName() { return "AurionAppnext"; }
11
+ private AppnextMeasurement.Completion callback(Promise promise) { return (result,error)->{if(error!=null)promise.reject(error,"Measurement pending; retry explicitly. No campaign actions performed.");else try{java.util.Map<String,Object> values=new java.util.HashMap<>();java.util.Iterator<String> keys=result.keys();while(keys.hasNext()){String key=keys.next();values.put(key,result.get(key));}promise.resolve(Arguments.makeNativeMap(values));}catch(Exception failure){promise.reject("E_RESULT","Invalid native result");}}; }
12
+ @ReactMethod public void configure(ReadableMap options, Promise promise) {
13
+ try { client=new AppnextMeasurement(getReactApplicationContext(),options.getString("apiKey"),options.getString("baseUrl"),options.getInt("appId"),options.hasKey("consent")&&options.getBoolean("consent"),options.hasKey("test")&&options.getBoolean("test"));client.start(options.hasKey("deepLink")?options.getString("deepLink"):null,callback(promise)); }
14
+ catch(Exception error){promise.reject("E_CONFIGURATION","Invalid native measurement configuration");}
15
+ }
16
+ @ReactMethod public void setConsent(boolean value,Promise promise){if(client==null){promise.reject("E_NOT_CONFIGURED","Configure first");return;}client.setConsent(value,callback(promise));}
17
+ @ReactMethod public void track(String event,Promise promise){if(client==null){promise.reject("E_NOT_CONFIGURED","Configure first");return;}client.track(event,callback(promise));}
18
+ @ReactMethod public void applyDeepLink(String url,Promise promise){if(client==null){promise.reject("E_NOT_CONFIGURED","Configure first");return;}client.start(url,callback(promise));}
19
+ @ReactMethod public void registerAppleInstall(Promise promise){promise.resolve(Arguments.createMap());}
20
+ @ReactMethod public void updateAppleConversion(int value,Promise promise){promise.reject("E_UNSUPPORTED_PLATFORM","Apple only");}
21
+ }
@@ -0,0 +1,12 @@
1
+ package com.aurionsignal.measurement;
2
+ import com.facebook.react.ReactPackage;
3
+ import com.facebook.react.bridge.NativeModule;
4
+ import com.facebook.react.bridge.ReactApplicationContext;
5
+ import com.facebook.react.uimanager.ViewManager;
6
+ import java.util.Arrays;
7
+ import java.util.Collections;
8
+ import java.util.List;
9
+ public final class AurionAppnextPackage implements ReactPackage {
10
+ @Override public List<NativeModule> createNativeModules(ReactApplicationContext context){return Arrays.<NativeModule>asList(new AurionAppnextModule(context), new AurionInstallReferrerModule(context), new AurionPushModule(context), new AurionNetworkModule(context));}
11
+ @Override public List<ViewManager> createViewManagers(ReactApplicationContext context){return Collections.emptyList();}
12
+ }
@@ -0,0 +1,40 @@
1
+ package com.aurionsignal.measurement;
2
+
3
+ import com.android.installreferrer.api.InstallReferrerClient;
4
+ import com.android.installreferrer.api.InstallReferrerStateListener;
5
+ import com.facebook.react.bridge.Promise;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
+ import com.facebook.react.bridge.ReactMethod;
9
+
10
+ /** Exposes the Google Play install referrer to JavaScript. Resolves null when it is unavailable. */
11
+ public final class AurionInstallReferrerModule extends ReactContextBaseJavaModule {
12
+ public AurionInstallReferrerModule(ReactApplicationContext context) { super(context); }
13
+
14
+ @Override public String getName() { return "AurionInstallReferrer"; }
15
+
16
+ @ReactMethod public void getInstallReferrer(final Promise promise) {
17
+ try {
18
+ final InstallReferrerClient client = InstallReferrerClient.newBuilder(getReactApplicationContext()).build();
19
+ client.startConnection(new InstallReferrerStateListener() {
20
+ @Override public void onInstallReferrerSetupFinished(int responseCode) {
21
+ try {
22
+ if (responseCode == InstallReferrerClient.InstallReferrerResponse.OK) {
23
+ promise.resolve(client.getInstallReferrer().getInstallReferrer());
24
+ } else {
25
+ promise.resolve(null);
26
+ }
27
+ } catch (Exception ignored) {
28
+ promise.resolve(null);
29
+ } finally {
30
+ try { client.endConnection(); } catch (Exception ignored) { }
31
+ }
32
+ }
33
+
34
+ @Override public void onInstallReferrerServiceDisconnected() { }
35
+ });
36
+ } catch (Exception error) {
37
+ promise.resolve(null);
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,161 @@
1
+ package com.aurionsignal.measurement;
2
+
3
+ import android.content.Context;
4
+ import android.net.ConnectivityManager;
5
+ import android.net.Network;
6
+ import android.net.NetworkCapabilities;
7
+ import android.net.NetworkRequest;
8
+ import android.os.Build;
9
+ import com.facebook.react.bridge.Arguments;
10
+ import com.facebook.react.bridge.Promise;
11
+ import com.facebook.react.bridge.ReactApplicationContext;
12
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
13
+ import com.facebook.react.bridge.ReactMethod;
14
+ import com.facebook.react.bridge.WritableMap;
15
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
16
+
17
+ /**
18
+ * Native online/offline signals for the JS offline event queue — no NetInfo peer required.
19
+ */
20
+ public final class AurionNetworkModule extends ReactContextBaseJavaModule {
21
+ public static final String NAME = "AurionNetwork";
22
+ private static final String EVENT = "aurionNetworkChange";
23
+
24
+ private ConnectivityManager.NetworkCallback callback;
25
+ private boolean listening = false;
26
+ private Boolean lastOnline = null;
27
+
28
+ public AurionNetworkModule(ReactApplicationContext context) {
29
+ super(context);
30
+ }
31
+
32
+ @Override
33
+ public String getName() {
34
+ return NAME;
35
+ }
36
+
37
+ @ReactMethod
38
+ public void isOnline(Promise promise) {
39
+ promise.resolve(currentlyOnline());
40
+ }
41
+
42
+ @ReactMethod
43
+ public void start(Promise promise) {
44
+ ensureListening();
45
+ promise.resolve(currentlyOnline());
46
+ }
47
+
48
+ @ReactMethod
49
+ public void addListener(String eventName) {
50
+ ensureListening();
51
+ }
52
+
53
+ @ReactMethod
54
+ public void removeListeners(Integer count) {
55
+ /* RN event emitter bookkeeping */
56
+ }
57
+
58
+ @Override
59
+ public void invalidate() {
60
+ stopListening();
61
+ super.invalidate();
62
+ }
63
+
64
+ private void ensureListening() {
65
+ if (listening) {
66
+ return;
67
+ }
68
+ ReactApplicationContext context = getReactApplicationContext();
69
+ ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
70
+ if (cm == null) {
71
+ return;
72
+ }
73
+ callback = new ConnectivityManager.NetworkCallback() {
74
+ @Override
75
+ public void onAvailable(Network network) {
76
+ emitOnline(true);
77
+ }
78
+
79
+ @Override
80
+ public void onLost(Network network) {
81
+ emitOnline(currentlyOnline());
82
+ }
83
+
84
+ @Override
85
+ public void onCapabilitiesChanged(Network network, NetworkCapabilities caps) {
86
+ emitOnline(caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
87
+ && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED));
88
+ }
89
+ };
90
+ try {
91
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
92
+ cm.registerDefaultNetworkCallback(callback);
93
+ } else {
94
+ cm.registerNetworkCallback(new NetworkRequest.Builder().build(), callback);
95
+ }
96
+ listening = true;
97
+ emitOnline(currentlyOnline());
98
+ } catch (Exception ignored) {
99
+ listening = false;
100
+ }
101
+ }
102
+
103
+ private void stopListening() {
104
+ if (!listening || callback == null) {
105
+ return;
106
+ }
107
+ try {
108
+ ConnectivityManager cm = (ConnectivityManager) getReactApplicationContext()
109
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
110
+ if (cm != null) {
111
+ cm.unregisterNetworkCallback(callback);
112
+ }
113
+ } catch (Exception ignored) {
114
+ /* ignore */
115
+ }
116
+ callback = null;
117
+ listening = false;
118
+ }
119
+
120
+ private boolean currentlyOnline() {
121
+ try {
122
+ ConnectivityManager cm = (ConnectivityManager) getReactApplicationContext()
123
+ .getSystemService(Context.CONNECTIVITY_SERVICE);
124
+ if (cm == null) {
125
+ return true;
126
+ }
127
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
128
+ Network network = cm.getActiveNetwork();
129
+ if (network == null) {
130
+ return false;
131
+ }
132
+ NetworkCapabilities caps = cm.getNetworkCapabilities(network);
133
+ return caps != null
134
+ && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
135
+ && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
136
+ }
137
+ @SuppressWarnings("deprecation")
138
+ android.net.NetworkInfo info = cm.getActiveNetworkInfo();
139
+ return info != null && info.isConnected();
140
+ } catch (Exception ignored) {
141
+ return true;
142
+ }
143
+ }
144
+
145
+ private void emitOnline(boolean online) {
146
+ if (lastOnline != null && online == lastOnline) {
147
+ return;
148
+ }
149
+ lastOnline = online;
150
+ ReactApplicationContext context = getReactApplicationContext();
151
+ if (!context.hasActiveReactInstance()) {
152
+ return;
153
+ }
154
+ WritableMap map = Arguments.createMap();
155
+ map.putBoolean("isConnected", online);
156
+ map.putBoolean("isInternetReachable", online);
157
+ context
158
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
159
+ .emit(EVENT, map);
160
+ }
161
+ }
@@ -0,0 +1,86 @@
1
+ package com.aurionsignal.measurement;
2
+
3
+ import android.content.Context;
4
+ import com.facebook.react.bridge.Promise;
5
+ import com.facebook.react.bridge.ReactApplicationContext;
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
7
+ import com.facebook.react.bridge.ReactMethod;
8
+ import com.facebook.react.bridge.ReadableMap;
9
+ import com.google.android.gms.ads.identifier.AdvertisingIdClient;
10
+ import com.google.firebase.FirebaseApp;
11
+ import com.google.firebase.FirebaseOptions;
12
+ import com.google.firebase.messaging.FirebaseMessaging;
13
+
14
+ /** Secondary FirebaseApp ("aurion") for uninstall probes — does not replace the host app's default Firebase. */
15
+ public final class AurionPushModule extends ReactContextBaseJavaModule {
16
+ public static final String APP_NAME = "aurion";
17
+
18
+ public AurionPushModule(ReactApplicationContext context) {
19
+ super(context);
20
+ }
21
+
22
+ @Override
23
+ public String getName() {
24
+ return "AurionPush";
25
+ }
26
+
27
+ @ReactMethod
28
+ public void start(ReadableMap options, Promise promise) {
29
+ try {
30
+ Context context = getReactApplicationContext();
31
+ FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
32
+ .setApplicationId(required(options, "appId"))
33
+ .setApiKey(required(options, "apiKey"))
34
+ .setProjectId(required(options, "projectId"))
35
+ .setGcmSenderId(required(options, "messagingSenderId"));
36
+ if (options.hasKey("storageBucket") && !options.isNull("storageBucket")) {
37
+ builder.setStorageBucket(options.getString("storageBucket"));
38
+ }
39
+ FirebaseApp app;
40
+ try {
41
+ app = FirebaseApp.getInstance(APP_NAME);
42
+ } catch (IllegalStateException missing) {
43
+ app = FirebaseApp.initializeApp(context, builder.build(), APP_NAME);
44
+ }
45
+ // getInstance(FirebaseApp) is package-private in firebase-messaging 24.x;
46
+ // resolve the component from the named secondary app instead.
47
+ FirebaseMessaging messaging = app.get(FirebaseMessaging.class);
48
+ if (messaging == null) {
49
+ promise.reject("E_FCM_TOKEN", "FirebaseMessaging unavailable for Aurion app");
50
+ return;
51
+ }
52
+ messaging.getToken()
53
+ .addOnSuccessListener(token -> promise.resolve(token))
54
+ .addOnFailureListener(error -> promise.reject("E_FCM_TOKEN", error.getMessage(), error));
55
+ } catch (Exception error) {
56
+ promise.reject("E_AURION_PUSH", error.getMessage(), error);
57
+ }
58
+ }
59
+
60
+ @ReactMethod
61
+ public void getAdvertisingId(Promise promise) {
62
+ new Thread(() -> {
63
+ try {
64
+ AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(getReactApplicationContext());
65
+ if (info == null || info.isLimitAdTrackingEnabled()) {
66
+ promise.resolve(null);
67
+ return;
68
+ }
69
+ promise.resolve(info.getId());
70
+ } catch (Exception error) {
71
+ promise.resolve(null);
72
+ }
73
+ }).start();
74
+ }
75
+
76
+ private static String required(ReadableMap options, String key) {
77
+ if (!options.hasKey(key) || options.isNull(key)) {
78
+ throw new IllegalArgumentException("Missing Firebase option: " + key);
79
+ }
80
+ String value = options.getString(key);
81
+ if (value == null || value.isEmpty()) {
82
+ throw new IllegalArgumentException("Missing Firebase option: " + key);
83
+ }
84
+ return value;
85
+ }
86
+ }