Skip to content

Commit

Permalink
Merge branch 'app-ga' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
alan committed Aug 3, 2020
2 parents ea882cb + c6611d7 commit 27059f1
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
10 changes: 10 additions & 0 deletions electron/app/constants/ga.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"app_ids": {
"prod": "UA-141773487-6",
"dev": "UA-141773487-7"
},
"dimensions": {
"dev": "dimension1",
"version": "dimension2"
}
}
32 changes: 31 additions & 1 deletion electron/app/containers/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { remote, ipcRenderer } from "electron";
import React, { ReactNode, useState, useRef } from "react";
import React, { ReactNode, useState, useEffect, useRef } from "react";
import ReactGA from "react-ga";
import { Button, Modal, Label } from "semantic-ui-react";
import { Switch, Route, Link, Redirect, useRouteMatch } from "react-router-dom";

Expand All @@ -13,6 +14,7 @@ import {
} from "../actions/update";
import { getSocket, useSubscribe } from "../utils/socket";
import connect from "../utils/connect";
import gaConfig from "../constants/ga.json";

type Props = {
children: ReactNode;
Expand All @@ -33,6 +35,34 @@ function App(props: Props) {
const portRef = useRef();
const [result, setResultFromForm] = useState({ port, connected });
const [socket, setSocket] = useState(getSocket(result.port, "state"));
const [gaInitialized, setGAInitialized] = useState(false);
useEffect(() => {
const dev = process.env.NODE_ENV == "development";
const buildType = dev ? "dev" : "prod";
socket.emit("get_fiftyone_info", (info) => {
ReactGA.initialize(gaConfig.app_ids[buildType], {
debug: dev,
gaOptions: {
storage: "none",
cookieDomain: "none",
clientId: info.user_id,
},
});
ReactGA.set({
userId: info.user_id,
checkProtocolTask: null, // disable check, allow file:// URLs
[gaConfig.dimensions.dev]: buildType,
[gaConfig.dimensions.version]: info.version,
});
setGAInitialized(true);
ReactGA.pageview(window.location.hash.replace(/^#/, ""));
});
}, []);
useEffect(() => {
if (gaInitialized) {
ReactGA.pageview(window.location.hash.replace(/^#/, ""));
}
}, [window.location.hash]);
useSubscribe(socket, "connect", () => {
dispatch(updateConnected(true));
if (loading) {
Expand Down
1 change: 1 addition & 0 deletions electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
"raw-loader": "^4.0.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-ga": "^3.1.2",
"react-grid-gallery": "^0.5.5",
"react-highlight": "^0.12.0",
"react-highlight.js": "^1.0.7",
Expand Down
5 changes: 5 additions & 0 deletions electron/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12494,6 +12494,11 @@ react-dom@^16.12.0:
prop-types "^15.6.2"
scheduler "^0.18.0"

react-ga@^3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.1.2.tgz#e13f211c51a2e5c401ea69cf094b9501fe3c51ce"
integrity sha512-OJrMqaHEHbodm+XsnjA6ISBEHTwvpFrxco65mctzl/v3CASMSLSyUkFqz9yYrPDKGBUfNQzKCjuMJwctjlWBbw==

react-grid-gallery@^0.5.5:
version "0.5.5"
resolved "https://registry.yarnpkg.com/react-grid-gallery/-/react-grid-gallery-0.5.5.tgz#1b3f3c23a190834e587ab613c96d53ec3af4f0a2"
Expand Down
25 changes: 25 additions & 0 deletions fiftyone/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import json
import logging
import os
import uuid

from bson import json_util
from flask import Flask, jsonify, request, send_file
Expand All @@ -46,6 +47,23 @@
socketio = SocketIO(app, async_mode="eventlet", cors_allowed_origins="*")


def get_user_id():
uid_path = os.path.join(foc.FIFTYONE_CONFIG_DIR, "var", "uid")

def read():
try:
with open(uid_path) as f:
return next(f).strip()
except (IOError, StopIteration):
return None

if not read():
os.makedirs(os.path.dirname(uid_path), exist_ok=True)
with open(uid_path, "w") as f:
f.write(str(uuid.uuid4()))
return read()


@app.route("/")
def get_sample_media():
"""Gets the sample media.
Expand Down Expand Up @@ -105,6 +123,13 @@ def on_update(self, state):
self.state = state
emit("update", state, broadcast=True, include_self=False)

def on_get_fiftyone_info(self):
"""Retrieves information about the FiftyOne installation."""
return {
"version": foc.VERSION,
"user_id": get_user_id(),
}

def on_get_current_state(self, _):
"""Gets the current state.
Expand Down

0 comments on commit 27059f1

Please sign in to comment.