Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add new user analytics

ammarahm-ed1abf080ca2c0
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index eab4d10ea..061acb055 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -32,7 +32,7 @@ let databaseHasLoaded = false;
async function loadDefaultNotes() {
try {
return true;
- /* const isCreated = await MMKV.getItem('defaultNoteCreated');
+ /* const isCreated = await MMKV.getItem('defaultNoteCreated');
if (isCreated) return;
const notes = await http.get(
'https://app.notesnook.com/notes/index_v14.json'
@@ -124,7 +124,7 @@ const App = () => {
await loadDatabase();
useUserStore.getState().setUser(await db.user.getUser());
if (SettingsService.get().telemetry) {
- Tracker.record('50bf361f-dba0-41f1-9570-93906249a6d3');
+ Tracker.record('3c6890ce-8410-49d5-8831-15fb2eb28a21');
}
} catch (e) {
} finally {
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 6b7b7e62f..d873e55b2 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -34,6 +34,7 @@ import Input from '../Input';
import {Header} from '../SimpleList/header';
import Paragraph from '../Typography/Paragraph';
import {ActionIcon} from '../ActionIcon';
+import umami from '../../utils/umami';
const MODES = {
login: 0,
@@ -319,6 +320,7 @@ const LoginDialog = () => {
clearMessage();
setEmailVerifyMessage();
close();
+ umami.pageView('/account-created', '/welcome/signup');
await sleep(300);
eSendEvent(eOpenResultDialog);
} catch (e) {
diff --git a/apps/mobile/src/components/Menu/index.js b/apps/mobile/src/components/Menu/index.js
index 7636a8cc8..f58e41a5c 100644
--- a/apps/mobile/src/components/Menu/index.js
+++ b/apps/mobile/src/components/Menu/index.js
@@ -19,6 +19,7 @@ import {
import {eOpenPremiumDialog} from '../../utils/Events';
import {MenuItemsList, SUBSCRIPTION_STATUS} from '../../utils/index';
import {MMKV} from '../../utils/mmkv';
+import umami from '../../utils/umami';
import {ColorSection} from './ColorSection';
import {MenuListItem} from './MenuListItem';
import {TagsSection} from './TagsSection';
@@ -65,6 +66,7 @@ export const Menu = React.memo(
name: 'Notesnook Pro',
icon: 'crown',
func: () => {
+ umami.pageView("/pro-screen","/sidemenu");
eSendEvent(eOpenPremiumDialog);
}
};
diff --git a/apps/mobile/src/components/Premium/component.js b/apps/mobile/src/components/Premium/component.js
index b694cb0d9..e0ce2aa30 100644
--- a/apps/mobile/src/components/Premium/component.js
+++ b/apps/mobile/src/components/Premium/component.js
@@ -1,24 +1,25 @@
-import React, { useState } from 'react';
-import { ScrollView, View } from 'react-native';
-import { LAUNCH_ROCKET } from '../../assets/images/assets';
-import { useTracked } from '../../provider';
-import { useUserStore } from '../../provider/stores';
-import { DDS } from '../../services/DeviceDetection';
-import { eSendEvent, presentSheet } from '../../services/EventManager';
-import { getElevation } from '../../utils';
-import { eOpenLoginDialog } from '../../utils/Events';
-import { SIZE } from '../../utils/SizeUtils';
-import { ActionIcon } from '../ActionIcon';
-import { Button } from '../Button';
+import React, {useState} from 'react';
+import {ScrollView, View} from 'react-native';
+import {LAUNCH_ROCKET} from '../../assets/images/assets';
+import {useTracked} from '../../provider';
+import {useUserStore} from '../../provider/stores';
+import {DDS} from '../../services/DeviceDetection';
+import {eSendEvent, presentSheet} from '../../services/EventManager';
+import {getElevation} from '../../utils';
+import {eOpenLoginDialog} from '../../utils/Events';
+import {SIZE} from '../../utils/SizeUtils';
+import umami from '../../utils/umami';
+import {ActionIcon} from '../ActionIcon';
+import {Button} from '../Button';
import GeneralSheet from '../GeneralSheet';
-import { SvgToPngView } from '../ListPlaceholders';
+import {SvgToPngView} from '../ListPlaceholders';
import Seperator from '../Seperator';
-import { Toast } from '../Toast';
+import {Toast} from '../Toast';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
-import { features } from './features';
-import { Group } from './group';
-import { PricingPlans } from './pricing-plans';
+import {features} from './features';
+import {Group} from './group';
+import {PricingPlans} from './pricing-plans';
export const Component = ({close, promo, getRef}) => {
const [state, dispatch] = useTracked();
@@ -28,12 +29,14 @@ export const Component = ({close, promo, getRef}) => {
const onPress = async () => {
if (user) {
+ umami.pageView('/pro-plans', `/pro-screen`);
presentSheet({
context: 'pricing_plans',
- component: <PricingPlans marginTop={1} promo={promo} />,
+ component: <PricingPlans marginTop={1} promo={promo} />
});
} else {
close();
+ umami.pageView('/signup', `/pro-screen`);
setTimeout(() => {
eSendEvent(eOpenLoginDialog, 1);
}, 400);
diff --git a/apps/mobile/src/components/Premium/pricingplans.js b/apps/mobile/src/components/Premium/pricingplans.js
index faa887a97..5fbfbfe3c 100644
--- a/apps/mobile/src/components/Premium/pricingplans.js
+++ b/apps/mobile/src/components/Premium/pricingplans.js
@@ -19,6 +19,7 @@ import {
import {openLinkInBrowser} from '../../utils/functions';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
+import umami from '../../utils/umami';
import {Button} from '../Button';
import {Dialog} from '../Dialog';
import BaseDialog from '../Dialog/base-dialog';
@@ -131,6 +132,10 @@ export const PricingPlans = ({
setBuying(false);
return;
}
+ umami.pageView(
+ '/iap-native',
+ `${compact ? 'pro-sheet' : 'pro-screen'}/pro-plans`
+ );
await RNIap.requestSubscription(
product?.productId,
false,
@@ -150,7 +155,7 @@ export const PricingPlans = ({
eSendEvent(eCloseProgressDialog);
},
icon: 'check',
- actionText: 'Continue',
+ actionText: 'Continue'
});
} catch (e) {
setBuying(false);
@@ -290,9 +295,13 @@ export const PricingPlans = ({
}}
title="I have a promo code"
/>
- ) : <View style={{
- height:15
- }} />}
+ ) : (
+ <View
+ style={{
+ height: 15
+ }}
+ />
+ )}
</>
) : (
<View>
@@ -314,7 +323,8 @@ export const PricingPlans = ({
marginBottom: 10
}}
/>
- {Platform.OS !== "ios" && promo &&
+ {Platform.OS !== 'ios' &&
+ promo &&
!promo.promoCode.startsWith('com.streetwriters.notesnook') ? (
<Paragraph
size={SIZE.md}
diff --git a/apps/mobile/src/components/SplashScreen/index.js b/apps/mobile/src/components/SplashScreen/index.js
index d90534a28..e58f702c4 100644
--- a/apps/mobile/src/components/SplashScreen/index.js
+++ b/apps/mobile/src/components/SplashScreen/index.js
@@ -22,6 +22,7 @@ import {openLinkInBrowser} from '../../utils/functions';
import {MMKV} from '../../utils/mmkv';
import {SIZE} from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils';
+import umami from '../../utils/umami';
import {Button} from '../Button';
import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph';
@@ -99,6 +100,7 @@ const SplashScreen = () => {
useEffect(() => {
if (!isIntroCompleted) {
+ umami.pageView('/welcome', '', []);
setTimeout(() => {
timing(opacity, {
toValue: 1,
@@ -202,11 +204,12 @@ const SplashScreen = () => {
await MMKV.setItem('introCompleted', 'true');
await sleep(300);
eSendEvent(eOpenLoginDialog, 1);
+ umami.pageView('/signup', '/welcome');
}
}}
style={{
paddingHorizontal: 24,
- alignSelf:'center'
+ alignSelf: 'center'
}}
type="accent"
title={isNext ? 'Next' : 'Sign up'}
@@ -220,17 +223,18 @@ const SplashScreen = () => {
onPress={async () => {
await hide();
await MMKV.setItem('introCompleted', 'true');
+ umami.pageView('/home', '/welcome');
}}
style={{
paddingHorizontal: 24,
- alignSelf:'center',
+ alignSelf: 'center',
marginTop: 10
}}
type="grayBg"
buttonType={{
color: '#808080',
selected: '#808080',
- opacity: 0.15,
+ opacity: 0.15
}}
title="I want to try the app first"
/>
diff --git a/apps/mobile/src/services/Message.js b/apps/mobile/src/services/Message.js
index 0925780ce..1354c2576 100644
--- a/apps/mobile/src/services/Message.js
+++ b/apps/mobile/src/services/Message.js
@@ -9,6 +9,7 @@ import PremiumService from './PremiumService';
import {verifyUser} from '../views/Settings/functions';
import {MMKV} from '../utils/mmkv';
import {Platform} from 'react-native';
+import umami from '../utils/umami';
const rateAppMessage = {
visible: true,
@@ -60,6 +61,7 @@ const loginMessage = {
message: 'You are not logged in',
actionText: 'Login to encrypt and sync notes',
onPress: () => {
+ umami.pageView('/signup', '/welcome/home');
eSendEvent(eOpenLoginDialog);
},
data: {},
diff --git a/apps/mobile/src/utils/umami.js b/apps/mobile/src/utils/umami.js
new file mode 100644
index 000000000..3b54014cb
--- /dev/null
+++ b/apps/mobile/src/utils/umami.js
@@ -0,0 +1,135 @@
+import {Platform} from 'react-native';
+import {MMKV} from './mmkv';
+import {useSettingStore} from '../provider/stores';
+
+const WEBSITE_ID = `3c6890ce-8410-49d5-8831-15fb2eb28a21`;
+const baseUrl = `https://analytics.streetwriters.co/api/collect`;
+
+const UA =
+ Platform.OS === 'ios'
+ ? `Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1`
+ : `
+Mozilla/5.0 (Linux; Android 8.0.0; SM-G960F Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36`;
+
+/**
+ *
+ * @param {Routes} route
+ * @param {Routes[]} conditions
+ * @returns
+ */
+async function canUpdateAnalytics(route, conditions = []) {
+ if (!useSettingStore?.getState()?.settings?.telemetry) return false;
+ let eventsList = await MMKV.getItem('notesnookUserEvents');
+
+ if (eventsList) {
+ eventsList = JSON.parse(eventsList);
+ }
+
+ if (eventsList && eventsList[route]) {
+ console.log('analytics: event already sent', route);
+ return false;
+ }
+ if (route !== '/welcome') {
+ for (cond of conditions) {
+ if (!eventsList || !eventsList[cond]) {
+ console.log('analytics: conditions not met for event', route, cond);
+ return false;
+ }
+ }
+ }
+ console.log('analytics: will send event', route);
+ return true;
+}
+
+async function saveAnalytics(route, value = true) {
+ let eventsList = await MMKV.getItem('notesnookUserEvents');
+ if (eventsList) {
+ eventsList = JSON.parse(eventsList);
+ } else {
+ eventsList = {};
+ }
+ eventsList[route] = value;
+ await MMKV.setItem('notesnookUserEvents', JSON.stringify(eventsList));
+}
+
+/**
+ *@typedef {"/welcome" | "/home" | "/signup" | "/first-note" | "/account-created" | "/pro-sheet" | "/pro-plans" | "/iap-native" | "/pro-screen" | "/editor" | "/editor-toolbar" | "/properties" | "/sidemenu"} Routes
+ * @param {Routes} prevRoute
+ * @param {Routes} route
+ * @param {Routes[]} conditions
+ * @param {boolean} once
+ * @returns
+ */
+
+async function pageView(
+ route,
+ prevRoute = '',
+ conditions = ['/welcome'],
+ once = true
+) {
+ if (!(await canUpdateAnalytics(route, conditions)) && once) return;
+ let body = {
+ payload: {
+ website: WEBSITE_ID,
+ url: `notesnook-${Platform.OS}${prevRoute}${route}`,
+ referrer: `https://notesnook.com/notesnook-${Platform.OS}${prevRoute}`,
+ hostname: `notesnook-${Platform.OS}`,
+ language: 'en-US',
+ screen: '1920x1080'
+ },
+ type: 'pageview'
+ };
+
+ try {
+ let response = await fetch(baseUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'User-Agent': UA
+ },
+ body: JSON.stringify(body)
+ });
+ console.log('analytics: event sent', route);
+ await saveAnalytics(route);
+ return await response.text();
+ } catch (e) {
+ console.log(e);
+ }
+}
+
+async function sendEvent(type, value, once = true) {
+ if (!(await canUpdateAnalytics(type)) && once) return;
+ let body = {
+ payload: {
+ website: WEBSITE_ID,
+ url: '/',
+ event_type: type,
+ event_value: value,
+ hostname: 'notesnook-android-app',
+ language: 'en-US',
+ screen: '1920x1080'
+ },
+ type: 'event'
+ };
+
+ try {
+ let response = await fetch(baseUrl, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'User-Agent': UA
+ },
+ body: JSON.stringify(body)
+ });
+ console.log(response.status);
+ return await response.text();
+ } catch (e) {
+ console.log(e);
+ }
+}
+
+export default {
+ sendEvent,
+ pageView,
+ saveAnalytics
+};
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.js
index 5a80a32af..93e832192 100644
--- a/apps/mobile/src/views/Editor/EditorHeader.js
+++ b/apps/mobile/src/views/Editor/EditorHeader.js
@@ -38,6 +38,7 @@ import {
eOpenPublishNoteDialog
} from '../../utils/Events';
import {tabBarRef} from '../../utils/Refs';
+import umami from '../../utils/umami';
import {EditorTitle} from './EditorTitle';
import {
clearEditor,
@@ -335,6 +336,7 @@ const EditorHeader = () => {
safeKeyboardDismiss();
editing.isFocused = true;
}
+ umami.pageView("/pro-screen","/editor")
eSendEvent(eOpenPremiumDialog);
}}
/>
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 24e93be2c..8b01de29a 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -27,6 +27,7 @@ import { MMKV } from '../../utils/mmkv';
import { tabBarRef } from '../../utils/Refs';
import { normalize } from '../../utils/SizeUtils';
import { sleep, timeConverter } from '../../utils/TimeUtils';
+import umami from '../../utils/umami';
import { TableCellProperties } from './TableCellProperties';
import { TableRowProperties } from './TableRowProperties';
import tiny from './tiny/tiny';
@@ -269,7 +270,7 @@ export const loadNote = async item => {
eSendEvent('loadingNote', item);
await clearEditor();
}
-
+ umami.pageView('/first-note', '/welcome/home');
clearNote();
eSendEvent('loadingNote');
eSendEvent('updateTags');
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/item.js b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
index 0c2b53da6..018cc007c 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/item.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/item.js
@@ -15,6 +15,7 @@ import { editing, showTooltip, TOOLTIP_POSITIONS } from '../../../../utils';
import { db } from '../../../../utils/database';
import { MMKV } from '../../../../utils/mmkv';
import { normalize, SIZE } from '../../../../utils/SizeUtils';
+import umami from '../../../../utils/umami';
import tiny, { safeKeyboardDismiss } from '../tiny';
import { execCommands } from './commands';
import {
@@ -214,6 +215,7 @@ const ToolbarItem = ({
if (user && !isPro && !user.isEmailConfirmed) {
PremiumService.showVerifyEmailDialog();
} else {
+ umami.pageView("/pro-sheet","/editor/editor-toolbar")
PremiumService.sheet();
}
return;
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index b460111e8..c02f0cd57 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -12,7 +12,6 @@ import SearchService from '../../services/SearchService';
import {editing, InteractionManager, scrollRef} from '../../utils';
import {db} from '../../utils/database';
import {eOnLoadNote} from '../../utils/Events';
-import {getLinkPreview} from '../../utils/linkpreview';
import {tabBarRef} from '../../utils/Refs';
import {getNote} from '../Editor/Functions';
@@ -80,13 +79,6 @@ export const Home = ({navigation}) => {
};
const _onPressBottomButton = React.useCallback(async () => {
- getLinkPreview('https://google.com')
- .then(r => {
- console.log(r);
- })
- .catch(console.log);
- return;
-
if (!DDS.isTab) {
if (getNote()) {
eSendEvent(eOnLoadNote, {type: 'new'});