-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add telemetry NativeVision is looking to understand how our users are using the library better. To do this, we've created a telemetry API to ingest events from the application. * Use deployed domain * chore: version bump 2.24.0 * Run typescript build
- Loading branch information
1 parent
a380420
commit 52a330e
Showing
20 changed files
with
270 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ local.properties | |
build/ | ||
*.tgz | ||
yarn.lock | ||
.env | ||
|
||
# Fastlane | ||
ios/fastlane/report.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { VIRO_VERSION } from "../Utilities/ViroVersion"; | ||
import { Platform } from "react-native"; | ||
|
||
export class ViroTelemetry { | ||
private static _isDisabled = false; | ||
private static _isDebugging = false; | ||
// TODO: use custom domain | ||
// private static _telemetryUrl = "https://telemetry.nativevision.xyz"; | ||
private static _telemetryUrl = "https://native-vision-telemetry.onrender.com"; | ||
private static _timeout = 8000; | ||
|
||
/** | ||
* Allow a user to start debugging the telemetry to see what is sent. | ||
*/ | ||
public static setDebugging() { | ||
this._isDebugging = true; | ||
} | ||
|
||
/** | ||
* Allow a user to opt out of telemetry. | ||
*/ | ||
public static optOutTelemetry() { | ||
this._isDisabled = true; | ||
} | ||
|
||
public static recordTelemetry(eventName: string, payload: any = {}) { | ||
// Skip recording telemetry if the feature is disabled | ||
if (this._isDisabled) return; | ||
// Do not send the telemetry data if debugging. Users may use this feature | ||
// to preview what data would be sent. | ||
if (this._isDebugging) { | ||
console.log( | ||
`[telemetry] ` + JSON.stringify({ eventName, payload }, null, 2) | ||
); | ||
return; | ||
} | ||
const controller = new AbortController(); | ||
const timeoutId = setTimeout(() => controller.abort(), this._timeout); | ||
|
||
payload = { ...payload, ...this.getAnonymousMeta() }; | ||
|
||
fetch(`${this._telemetryUrl}/api/v1/record`, { | ||
method: "PUT", | ||
body: JSON.stringify({ eventName, payload }), | ||
headers: { "content-type": "application/json" }, | ||
signal: controller.signal, | ||
}) | ||
.catch((e) => console.error(e)) | ||
.finally(() => clearTimeout(timeoutId)); | ||
} | ||
|
||
private static getAnonymousMeta() { | ||
let isExpo = false; | ||
try { | ||
const myModule = require("expo"); | ||
isExpo = true; | ||
} catch (err) { | ||
// send error to log file | ||
} | ||
|
||
try { | ||
const traits = { | ||
// expo | ||
isExpo: | ||
// @ts-ignore | ||
Boolean(window?.expo) || false, | ||
sdkVersion: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.sdkVersion || undefined, | ||
androidPackage: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.android?.package || | ||
undefined, | ||
iosBundleIdentifier: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.ios?.bundleIdentifier || | ||
undefined, | ||
expoDebugMode: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.debugMode || undefined, | ||
isDevice: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.isDevice || undefined, | ||
// library version | ||
viroVersion: VIRO_VERSION, | ||
platform: Platform.OS, | ||
deviceOsVersion: Platform.Version, | ||
reactNativeVersion: | ||
Platform.constants.reactNativeVersion.major + | ||
"." + | ||
Platform.constants.reactNativeVersion.minor + | ||
"." + | ||
Platform.constants.reactNativeVersion.patch, | ||
}; | ||
|
||
return traits; | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const VIRO_VERSION = "2.40.0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export declare class ViroTelemetry { | ||
private static _isDisabled; | ||
private static _isDebugging; | ||
private static _telemetryUrl; | ||
private static _timeout; | ||
/** | ||
* Allow a user to start debugging the telemetry to see what is sent. | ||
*/ | ||
static setDebugging(): void; | ||
/** | ||
* Allow a user to opt out of telemetry. | ||
*/ | ||
static optOutTelemetry(): void; | ||
static recordTelemetry(eventName: string, payload?: any): void; | ||
private static getAnonymousMeta; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ViroTelemetry = void 0; | ||
const ViroVersion_1 = require("../Utilities/ViroVersion"); | ||
const react_native_1 = require("react-native"); | ||
class ViroTelemetry { | ||
static _isDisabled = false; | ||
static _isDebugging = false; | ||
// TODO: use custom domain | ||
// private static _telemetryUrl = "https://telemetry.nativevision.xyz"; | ||
static _telemetryUrl = "https://native-vision-telemetry.onrender.com"; | ||
static _timeout = 8000; | ||
/** | ||
* Allow a user to start debugging the telemetry to see what is sent. | ||
*/ | ||
static setDebugging() { | ||
this._isDebugging = true; | ||
} | ||
/** | ||
* Allow a user to opt out of telemetry. | ||
*/ | ||
static optOutTelemetry() { | ||
this._isDisabled = true; | ||
} | ||
static recordTelemetry(eventName, payload = {}) { | ||
// Skip recording telemetry if the feature is disabled | ||
if (this._isDisabled) | ||
return; | ||
// Do not send the telemetry data if debugging. Users may use this feature | ||
// to preview what data would be sent. | ||
if (this._isDebugging) { | ||
console.log(`[telemetry] ` + JSON.stringify({ eventName, payload }, null, 2)); | ||
return; | ||
} | ||
const controller = new AbortController(); | ||
const timeoutId = setTimeout(() => controller.abort(), this._timeout); | ||
payload = { ...payload, ...this.getAnonymousMeta() }; | ||
fetch(`${this._telemetryUrl}/api/v1/record`, { | ||
method: "PUT", | ||
body: JSON.stringify({ eventName, payload }), | ||
headers: { "content-type": "application/json" }, | ||
signal: controller.signal, | ||
}) | ||
.catch((e) => console.error(e)) | ||
.finally(() => clearTimeout(timeoutId)); | ||
} | ||
static getAnonymousMeta() { | ||
let isExpo = false; | ||
try { | ||
const myModule = require("expo"); | ||
isExpo = true; | ||
} | ||
catch (err) { | ||
// send error to log file | ||
} | ||
try { | ||
const traits = { | ||
// expo | ||
isExpo: | ||
// @ts-ignore | ||
Boolean(window?.expo) || false, | ||
sdkVersion: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.sdkVersion || undefined, | ||
androidPackage: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.android?.package || | ||
undefined, | ||
iosBundleIdentifier: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.ios?.bundleIdentifier || | ||
undefined, | ||
expoDebugMode: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.debugMode || undefined, | ||
isDevice: | ||
// @ts-ignore | ||
window?.expo?.modules?.ExponentConstants?.isDevice || undefined, | ||
// library version | ||
viroVersion: ViroVersion_1.VIRO_VERSION, | ||
platform: react_native_1.Platform.OS, | ||
deviceOsVersion: react_native_1.Platform.Version, | ||
reactNativeVersion: react_native_1.Platform.constants.reactNativeVersion.major + | ||
"." + | ||
react_native_1.Platform.constants.reactNativeVersion.minor + | ||
"." + | ||
react_native_1.Platform.constants.reactNativeVersion.patch, | ||
}; | ||
return traits; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
} | ||
return {}; | ||
} | ||
} | ||
exports.ViroTelemetry = ViroTelemetry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export declare const VIRO_VERSION = "2.40.0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VIRO_VERSION = void 0; | ||
exports.VIRO_VERSION = "2.40.0"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.