Skip to content

Commit

Permalink
[PWA] Add fingerprint tId
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanem committed Feb 16, 2025
1 parent 224d321 commit 3212758
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"redux-thunk": "2.4.1",
"styled-components": "5.3.3",
"typescript": "4.5.5",
"fuzzysort": "3.1.0"
"fuzzysort": "3.1.0",
"get-browser-fingerprint": "4.1.0"
},
"devDependencies": {
"google-play-scraper": "9.1.1",
Expand Down
30 changes: 9 additions & 21 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React from 'react';
import { useTheme, useMediaQuery } from '@mui/material';
import { useSelector } from 'react-redux';
import pkg from '../package.json';
import { getCurrentDate, isDev, isEmpty, uuid } from './helpers';
import { getCurrentDate, isDev, isEmpty } from './helpers';
import useProcessData from './database/useProcessData';
import { tables } from './database/dbConfig';
import { useTrackingId } from './components/layout/store';
import getBrowserFingerprint from 'get-browser-fingerprint';

export const useFullScreen = (size = 'sm' as any) => {
const theme = useTheme();
Expand Down Expand Up @@ -134,25 +134,9 @@ export const useTracking = ({ isPwa = false }) => {
}, [trackingId, setTrackingId]);*/

React.useEffect(() => {
if (/*!isDev() &&*/ isClient && !isGoogleBot() && !isBingBot()) {
var trackingId;
try {
console.log('Getting tId...');
trackingId = localStorage.getItem('tId');
console.log('tId = ' + trackingId);
} catch (ex) {
console.error('Error getting tId', ex);
}

if (isEmpty(trackingId)) {
trackingId = uuid();
try {
console.log('Setting tId = ' + trackingId);
localStorage.setItem('tId', trackingId);
} catch (ex) {
console.error('Error setting tId', ex);
}
}
const runTracking = async () => {
const fingerPrint = await getBrowserFingerprint();
const trackingId = String(fingerPrint);
console.log({ trackingId });

if (!isEmpty(trackingId)) {
Expand Down Expand Up @@ -217,6 +201,10 @@ export const useTracking = ({ isPwa = false }) => {
}
});
}
};

if (/*!isDev() &&*/ isClient && !isGoogleBot() && !isBingBot()) {
runTracking();
} else {
console.log('Skipping track logic!');
}
Expand Down

0 comments on commit 3212758

Please sign in to comment.