Skip to content

Commit

Permalink
Feature/act 760 device performance to amplitude (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-wolf3d authored Aug 8, 2024
1 parent f7d3250 commit f7b329f
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 4 deletions.
176 changes: 172 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
]
},
"peerDependencies": {
"@amplitude/analytics-browser": "^1.13.6",
"@react-three/drei": "9.108.4",
"@react-three/fiber": "8.16.8",
"@react-three/postprocessing": "2.16.2",
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useDeviceDetector/use-device-detector.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { getGPUTier, TierResult as GpuTierResult } from 'detect-gpu';
import { stringify } from 'qs';
import { checkDownloadSpeed } from 'src/services/DownloadSpeed.service';
import { trackEvent } from 'src/services/Analytics.service';

type TierPresets = { [key: number]: Record<string, any> };

Expand Down Expand Up @@ -48,6 +49,8 @@ class DeviceDetectorService {
if (props.tierPresets) {
this.tierPresets = { ...TIER_PRESETS, ...props.tierPresets };
}

trackEvent('device detected', this.result);
}

get result() {
Expand Down
9 changes: 9 additions & 0 deletions src/services/Analytics.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { track } from '@amplitude/analytics-browser';

export function trackEvent(event: string, data?: Record<string, any>) {
try {
track(event, data);
} catch (error) {
console.error('Failed to track event', error);

Check warning on line 7 in src/services/Analytics.service.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected console statement
}
}

0 comments on commit f7b329f

Please sign in to comment.