Skip to content

Commit

Permalink
Move tId to localStorage key.
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanem committed Feb 16, 2025
1 parent 29f32d6 commit 224d321
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-map-db",
"version": "2.1.52",
"version": "2.1.53",
"private": true,
"homepage": "https://mindapps.org",
"enableLogRocket": true,
Expand Down
30 changes: 25 additions & 5 deletions src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,42 @@ export const trackingColumns = [
].map(name => ({ name }));

export const useTracking = ({ isPwa = false }) => {
const [trackingId, setTrackingId] = useTrackingId();
//const [trackingId, setTrackingId] = useTrackingId();

const installed = useUrlParameter('installed');

const processData = useProcessData();

React.useEffect(() => {
/*React.useEffect(() => {
if (isEmpty(trackingId)) {
const tId = uuid() as String;
console.log(`Setting id: ${tId}`);
setTrackingId(tId);
}
}, [trackingId, setTrackingId]);
}, [trackingId, setTrackingId]);*/

React.useEffect(() => {
if (!isDev() && isClient && !isGoogleBot() && !isBingBot()) {
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);
}
}
console.log({ trackingId });

if (!isEmpty(trackingId)) {
// Store tracking info
console.log('Reading metadata...');
Expand Down Expand Up @@ -200,5 +220,5 @@ export const useTracking = ({ isPwa = false }) => {
} else {
console.log('Skipping track logic!');
}
}, [trackingId, installed]);
}, [installed]);
};

0 comments on commit 224d321

Please sign in to comment.