Skip to content

Commit 52a330e

Browse files
Add Telemetry (#264)
* 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
1 parent a380420 commit 52a330e

20 files changed

+270
-24
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ local.properties
6161
build/
6262
*.tgz
6363
yarn.lock
64+
.env
6465

6566
# Fastlane
6667
ios/fastlane/report.xml

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# ViroReact
1212

13-
ViroReact is a library for developers to rapidly build augmented reality (AR) and virtual reality (VR) experiences. Developers write in React Native, and Viro runs their code natively across all mobile VR (including Google Daydream, Samsung Gear VR, and Google Cardboard for iOS and Android) and AR (iOS ARKit and Android ARCore) platforms.
13+
ViroReact is a library for developers to rapidly build augmented reality (AR) and virtual reality (VR) experiences. Developers write in React Native and Viro runs their code natively across all mobile VR (including Google Daydream, Samsung Gear VR, and Google Cardboard for iOS and Android) and AR (iOS ARKit and Android ARCore) platforms.
1414

1515
<table>
1616
<tr>
@@ -23,21 +23,17 @@ ViroReact is a library for developers to rapidly build augmented reality (AR) an
2323
</tr>
2424
</table>
2525

26-
# [Installing](readmes/INSTALL.md)
27-
28-
If you are integrating ViroReact into an existing project, have a look at our [Installation instructions](readmes/INSTALL.md).
29-
30-
If you are starting a fresh project with ViroReact, consider cloning our [starter kit](https://github.com/ViroCommunity/starter-kit) repo instead.
31-
3226
# Documentation
3327

34-
The documentation is found [here](https://viro-community.readme.io/docs/overview). Currently, the documentation is migrated with issues to code samples and broken links. If you would like to help fix these issues, either submit an edit or [get in touch](https://discord.gg/H3ksm5NhzT)!
28+
[Documentation can be found here!](https://viro-community.readme.io/docs/overview). Currently, the documentation has some issues with code samples and broken links. If you would like to help fix these issues, either submit an edit or [get in touch](https://discord.gg/H3ksm5NhzT)!
3529

36-
# FAQ
30+
## Getting Started
3731

38-
- _Older versions couldn't be submitted to Apple's app store due to use of `UIWebView`. Is this still a problem?_
32+
If you are starting a fresh project with ViroReact, consider cloning one of our starter kits:
3933

40-
Reliance on `UIWebView` has been removed from the project, so you should not have this problem if using the `@viro-community/react-viro` package.
34+
- [Expo + TypeScript](https://github.com/NativeVision/expo-starter-kit-typescript)
35+
- [React Native](https://github.com/NativeVision/starter-kit)
36+
- [Expo + JavaScript](https://github.com/NativeVision/expo-starter-kit)
4137

4238
# Examples
4339

components/AR/ViroARScene.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ViroBase } from "../ViroBase";
4747
import { ViroCamera } from "../ViroCamera";
4848
import { ViroTrackingStateConstants } from "../ViroConstants";
4949
import { ViroCommonProps } from "./ViroCommonProps";
50+
import { ViroTelemetry } from "../Telemetry";
5051

5152
const ViroCameraModule = NativeModules.ViroCameraModule;
5253

components/AR/ViroARSceneNavigator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
ViroScene,
2828
ViroSceneDictionary,
2929
} from "../Types/ViroUtils";
30+
import { ViroTelemetry } from "../Telemetry";
3031

3132
const ViroARSceneNavigatorModule = NativeModules.VRTARSceneNavigatorModule;
3233

@@ -79,6 +80,7 @@ export class ViroARSceneNavigator extends React.Component<Props, State> {
7980

8081
constructor(props: Props) {
8182
super(props);
83+
ViroTelemetry.recordTelemetry("INIT", { ar: true });
8284
let initialSceneTag = this.props.initialSceneKey;
8385
if (initialSceneTag == null) {
8486
initialSceneTag = this.getRandomTag();

components/Telemetry/index.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { VIRO_VERSION } from "../Utilities/ViroVersion";
2+
import { Platform } from "react-native";
3+
4+
export class ViroTelemetry {
5+
private static _isDisabled = false;
6+
private static _isDebugging = false;
7+
// TODO: use custom domain
8+
// private static _telemetryUrl = "https://telemetry.nativevision.xyz";
9+
private static _telemetryUrl = "https://native-vision-telemetry.onrender.com";
10+
private static _timeout = 8000;
11+
12+
/**
13+
* Allow a user to start debugging the telemetry to see what is sent.
14+
*/
15+
public static setDebugging() {
16+
this._isDebugging = true;
17+
}
18+
19+
/**
20+
* Allow a user to opt out of telemetry.
21+
*/
22+
public static optOutTelemetry() {
23+
this._isDisabled = true;
24+
}
25+
26+
public static recordTelemetry(eventName: string, payload: any = {}) {
27+
// Skip recording telemetry if the feature is disabled
28+
if (this._isDisabled) return;
29+
// Do not send the telemetry data if debugging. Users may use this feature
30+
// to preview what data would be sent.
31+
if (this._isDebugging) {
32+
console.log(
33+
`[telemetry] ` + JSON.stringify({ eventName, payload }, null, 2)
34+
);
35+
return;
36+
}
37+
const controller = new AbortController();
38+
const timeoutId = setTimeout(() => controller.abort(), this._timeout);
39+
40+
payload = { ...payload, ...this.getAnonymousMeta() };
41+
42+
fetch(`${this._telemetryUrl}/api/v1/record`, {
43+
method: "PUT",
44+
body: JSON.stringify({ eventName, payload }),
45+
headers: { "content-type": "application/json" },
46+
signal: controller.signal,
47+
})
48+
.catch((e) => console.error(e))
49+
.finally(() => clearTimeout(timeoutId));
50+
}
51+
52+
private static getAnonymousMeta() {
53+
let isExpo = false;
54+
try {
55+
const myModule = require("expo");
56+
isExpo = true;
57+
} catch (err) {
58+
// send error to log file
59+
}
60+
61+
try {
62+
const traits = {
63+
// expo
64+
isExpo:
65+
// @ts-ignore
66+
Boolean(window?.expo) || false,
67+
sdkVersion:
68+
// @ts-ignore
69+
window?.expo?.modules?.ExponentConstants?.sdkVersion || undefined,
70+
androidPackage:
71+
// @ts-ignore
72+
window?.expo?.modules?.ExponentConstants?.android?.package ||
73+
undefined,
74+
iosBundleIdentifier:
75+
// @ts-ignore
76+
window?.expo?.modules?.ExponentConstants?.ios?.bundleIdentifier ||
77+
undefined,
78+
expoDebugMode:
79+
// @ts-ignore
80+
window?.expo?.modules?.ExponentConstants?.debugMode || undefined,
81+
isDevice:
82+
// @ts-ignore
83+
window?.expo?.modules?.ExponentConstants?.isDevice || undefined,
84+
// library version
85+
viroVersion: VIRO_VERSION,
86+
platform: Platform.OS,
87+
deviceOsVersion: Platform.Version,
88+
reactNativeVersion:
89+
Platform.constants.reactNativeVersion.major +
90+
"." +
91+
Platform.constants.reactNativeVersion.minor +
92+
"." +
93+
Platform.constants.reactNativeVersion.patch,
94+
};
95+
96+
return traits;
97+
} catch (e) {
98+
console.error(e);
99+
}
100+
101+
return {};
102+
}
103+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const VIRO_VERSION = "2.40.0";

components/Viro3DSceneNavigator.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
ViroSceneDictionary,
2626
} from "./Types/ViroUtils";
2727
import { ViroScene } from "./ViroScene";
28+
import { ViroTelemetry } from "./Telemetry";
2829
const Viro3DSceneNavigatorModule = NativeModules.VRT3DSceneNavigatorModule;
2930

3031
var mathRandomOffset = 0;
@@ -93,6 +94,7 @@ export class Viro3DSceneNavigator extends React.Component<Props, State> {
9394

9495
constructor(props: Props) {
9596
super(props);
97+
ViroTelemetry.recordTelemetry("INIT", { vr: true });
9698
var initialSceneTag = this.props.initialSceneKey;
9799
if (initialSceneTag == null) {
98100
initialSceneTag = this.getRandomTag();

components/ViroSceneNavigator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ViroExitViroEvent } from "./Types/ViroEvents";
2525
import { Viro3DPoint } from "./Types/ViroUtils";
2626
import { ViroSceneDictionary } from "./Types/ViroUtils";
2727
import { ViroScene } from "./ViroScene";
28+
import { ViroTelemetry } from "./Telemetry";
2829
var ViroSceneNavigatorModule = NativeModules.VRTSceneNavigatorModule;
2930

3031
var mathRandomOffset = 0;

dist/components/AR/ViroARSceneNavigator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3737
exports.ViroARSceneNavigator = void 0;
3838
const React = __importStar(require("react"));
3939
const react_native_1 = require("react-native");
40+
const Telemetry_1 = require("../Telemetry");
4041
const ViroARSceneNavigatorModule = react_native_1.NativeModules.VRTARSceneNavigatorModule;
4142
let mathRandomOffset = 0;
4243
/**
@@ -46,6 +47,7 @@ class ViroARSceneNavigator extends React.Component {
4647
_component = null;
4748
constructor(props) {
4849
super(props);
50+
Telemetry_1.ViroTelemetry.recordTelemetry("INIT", { ar: true });
4951
let initialSceneTag = this.props.initialSceneKey;
5052
if (initialSceneTag == null) {
5153
initialSceneTag = this.getRandomTag();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export declare class ViroTelemetry {
2+
private static _isDisabled;
3+
private static _isDebugging;
4+
private static _telemetryUrl;
5+
private static _timeout;
6+
/**
7+
* Allow a user to start debugging the telemetry to see what is sent.
8+
*/
9+
static setDebugging(): void;
10+
/**
11+
* Allow a user to opt out of telemetry.
12+
*/
13+
static optOutTelemetry(): void;
14+
static recordTelemetry(eventName: string, payload?: any): void;
15+
private static getAnonymousMeta;
16+
}

0 commit comments

Comments
 (0)