From dcfc13f8d0daab6cebbc86f69b5465ffd30c57e2 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 28 Feb 2023 09:03:44 -0800 Subject: [PATCH] Add analytics identify() call with hashed email --- package.json | 1 + src/lib/analytics.web.tsx | 1 + src/view/com/login/CreateAccount.tsx | 8 +++++++- yarn.lock | 5 +++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e27a0bcc..083c802b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "email-validator": "^2.0.4", "he": "^1.2.0", "history": "^5.3.0", + "js-sha256": "^0.9.0", "lodash.chunk": "^4.2.0", "lodash.clonedeep": "^4.5.0", "lodash.isequal": "^4.5.0", diff --git a/src/lib/analytics.web.tsx b/src/lib/analytics.web.tsx index e2db537f..10488c30 100644 --- a/src/lib/analytics.web.tsx +++ b/src/lib/analytics.web.tsx @@ -5,6 +5,7 @@ import {RootStoreModel} from 'state/models/root-store' const _analytics = { screen(_name: string) {}, track(_name: string, _opts: any) {}, + identify(_userId: string, _userTraits: any) {}, } export const track = _analytics.track export function useAnalytics() { diff --git a/src/view/com/login/CreateAccount.tsx b/src/view/com/login/CreateAccount.tsx index 870013f3..28a432e8 100644 --- a/src/view/com/login/CreateAccount.tsx +++ b/src/view/com/login/CreateAccount.tsx @@ -15,6 +15,7 @@ import { } from '@fortawesome/react-native-fontawesome' import {ComAtprotoAccountCreate} from '@atproto/api' import * as EmailValidator from 'email-validator' +import {sha256} from 'js-sha256' import {useAnalytics} from 'lib/analytics' import {LogoTextHero} from './Logo' import {Picker} from '../util/Picker' @@ -29,7 +30,7 @@ import {usePalette} from 'lib/hooks/usePalette' import {cleanError} from 'lib/strings/errors' export const CreateAccount = ({onPressBack}: {onPressBack: () => void}) => { - const {track, screen} = useAnalytics() + const {track, screen, identify} = useAnalytics() const pal = usePalette('default') const store = useStores() const [isProcessing, setIsProcessing] = useState(false) @@ -114,6 +115,11 @@ export const CreateAccount = ({onPressBack}: {onPressBack: () => void}) => { password, inviteCode, }) + + const email_hashed = sha256(email) + identify(email_hashed, {email_hashed}) + console.log('identify', email_hashed) + track('Create Account') } catch (e: any) { let errMsg = e.toString() diff --git a/yarn.lock b/yarn.lock index b95af47d..4886fac7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8599,6 +8599,11 @@ js-sdsl@^4.1.4: resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.3.0.tgz#aeefe32a451f7af88425b11fdb5f58c90ae1d711" integrity sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ== +js-sha256@^0.9.0: + version "0.9.0" + resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966" + integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA== + "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"