Skip to content

Commit

Permalink
chore: add web version to amplitude events (#516)
Browse files Browse the repository at this point in the history
* add tag

* clean up

* a little less brittle

* update e2e osx to Monterey

---------

Co-authored-by: Bill He <[email protected]>
  • Loading branch information
moo-onthelawn and rosepuppy authored May 10, 2024
1 parent 1eb50ee commit c37ce2e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
},
"scripts": {
"dev": "cp ./template.html ./index.html && vite",
"build": "pnpm run build:set-last-commit && pnpm run build:generate-entry-points && tsc && vite build",
"build": "pnpm run build:set-last-commit-and-tag && pnpm run build:generate-entry-points && tsc && vite build",
"build:inject-app-deeplinks": "sh scripts/inject-app-deeplinks.sh",
"build:inject-amplitude": "node scripts/inject-amplitude.js",
"build:inject-bugsnag": "node scripts/inject-bugsnag.js",
"build:inject-intercom": "node scripts/inject-intercom.js",
"build:inject-statuspage": "node scripts/inject-statuspage.js",
"build:inject-smartbanner": "node scripts/inject-smartbanner.js",
"build:set-last-commit": "sh scripts/set-last-commit.sh",
"build:set-last-commit-and-tag": "sh scripts/set-last-commit-and-tag.sh",
"build:generate-entry-points": "node scripts/generate-entry-points.js",
"deploy:ipfs": "node scripts/upload-ipfs.js --verbose",
"deploy:update-ipns": "node scripts/update-ipns.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ if [ -z "$VITE_LAST_ORIGINAL_COMMIT" ]; then
exit 0
fi

# Find the tag the commit lives in
VITE_LAST_TAG=$(git describe --exact-match $VITE_LAST_ORIGINAL_COMMIT)

# Update or add VITE_LAST_ORIGINAL_COMMIT in .env
if grep -q "VITE_LAST_ORIGINAL_COMMIT=" .env; then
# Variable exists, replace it
Expand All @@ -26,4 +29,15 @@ else
echo "VITE_LAST_ORIGINAL_COMMIT=$VITE_LAST_ORIGINAL_COMMIT" >> .env
fi

echo "VITE_LAST_ORIGINAL_COMMIT set as $VITE_LAST_ORIGINAL_COMMIT"
echo "VITE_LAST_ORIGINAL_COMMIT set as $VITE_LAST_ORIGINAL_COMMIT"

# Update or add VITE_LAST_TAG in .env
if grep -q "VITE_LAST_TAG=" .env; then
# Variable exists, replace it
awk -v lc="$VITE_LAST_TAG" '/^VITE_LAST_TAG=/ {$0="VITE_LAST_TAG="lc} 1' .env > .env.tmp && mv .env.tmp .env
else
# Variable does not exist, append it
echo "VITE_LAST_TAG=$VITE_LAST_TAG" >> .env
fi

echo "VITE_LAST_TAG set as $VITE_LAST_TAG"
3 changes: 3 additions & 0 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum AnalyticsUserProperty {
// Environment
Locale = 'selectedLocale',
Breakpoint = 'breakpoint',
Version = 'version',

// Network
Network = 'network',
Expand All @@ -31,6 +32,8 @@ export type AnalyticsUserPropertyValue<T extends AnalyticsUserProperty> =
? 'MOBILE' | 'TABLET' | 'DESKTOP_SMALL' | 'DESKTOP_MEDIUM' | 'DESKTOP_LARGE' | 'UNSUPPORTED'
: T extends AnalyticsUserProperty.Locale
? SupportedLocales
: T extends AnalyticsUserProperty.Version
? string | undefined
: // Network
T extends AnalyticsUserProperty.Network
? DydxNetwork
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useDydxClient } from './useDydxClient';
import { useSelectedNetwork } from './useSelectedNetwork';

export const useAnalytics = () => {
const latestTag = import.meta.env.VITE_LAST_TAG;
const { walletType, walletConnectionType, evmAddress, dydxAddress, selectedWalletType } =
useAccounts();
const { indexerClient } = useDydxClient();
Expand Down Expand Up @@ -54,6 +55,13 @@ export const useAnalytics = () => {
identify(AnalyticsUserProperty.Locale, selectedLocale);
}, [selectedLocale]);

// AnalyticsUserProperty.Version
useEffect(() => {
if (latestTag !== undefined) {
identify(AnalyticsUserProperty.Version, latestTag.split(`release/v`).at(-1));
}
}, [latestTag]);

// AnalyticsUserProperty.Network
const { selectedNetwork } = useSelectedNetwork();

Expand Down
4 changes: 2 additions & 2 deletions wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export const config: Options.Testrunner = {
browserName: 'safari',
'bstack:options': {
os: 'OS X',
osVersion: 'Big Sur',
osVersion: 'Monterey',
},
},
{
browserName: 'chrome',
'bstack:options': {
os: 'OS X',
osVersion: 'Big Sur',
osVersion: 'Monterey',
},
},
{
Expand Down

0 comments on commit c37ce2e

Please sign in to comment.