Skip to content

Commit ffc8415

Browse files
committed
Update: Better Google Analytics integration
Create custom definitions of user_type & login_status to view logged in user activities across devices
1 parent e1a115a commit ffc8415

File tree

2 files changed

+109
-56
lines changed

2 files changed

+109
-56
lines changed

index.html

Lines changed: 88 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,102 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>TradingGoose AI - Multi-Agent Trading System</title>
8-
<meta name="description" content="AI-powered trading system with 11 specialized agents for comprehensive market analysis" />
9-
<meta name="author" content="TradingGoose" />
103

11-
<meta property="og:title" content="TradingGoose AI" />
12-
<meta property="og:description" content="AI-powered trading system with 11 specialized agents for comprehensive market analysis" />
13-
<meta property="og:type" content="website" />
14-
<meta property="og:image" content="/favicon.ico" />
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>TradingGoose AI - Multi-Agent Trading System</title>
9+
<meta name="description"
10+
content="AI-powered trading system with 11 specialized agents for comprehensive market analysis" />
11+
<meta name="author" content="TradingGoose" />
1512

16-
<meta name="twitter:card" content="summary_large_image" />
17-
<meta name="twitter:site" content="@tradinggoose" />
18-
<meta name="twitter:image" content="/favicon.ico" />
19-
20-
<!-- GitHub Pages SPA redirect handling -->
21-
<script type="text/javascript">
22-
// Single Page Apps for GitHub Pages
23-
// This script checks if a redirect is present and handles it
24-
(function(l) {
25-
if (l.search[1] === '/' ) {
26-
var decoded = l.search.slice(1).split('&').map(function(s) {
27-
return s.replace(/~and~/g, '&')
28-
}).join('?');
29-
window.history.replaceState(null, null,
30-
l.pathname.slice(0, -1) + decoded + l.hash
31-
);
32-
}
33-
}(window.location))
34-
</script>
35-
36-
<!-- GitHub OAuth redirect handler -->
37-
<script type="text/javascript">
13+
<meta property="og:title" content="TradingGoose AI" />
14+
<meta property="og:description"
15+
content="AI-powered trading system with 11 specialized agents for comprehensive market analysis" />
16+
<meta property="og:type" content="website" />
17+
<meta property="og:image" content="/favicon.ico" />
18+
19+
<meta name="twitter:card" content="summary_large_image" />
20+
<meta name="twitter:site" content="@tradinggoose" />
21+
<meta name="twitter:image" content="/favicon.ico" />
22+
23+
<!-- GitHub Pages SPA redirect handling -->
24+
<script type="text/javascript">
25+
// Single Page Apps for GitHub Pages
26+
// This script checks if a redirect is present and handles it
27+
(function (l) {
28+
if (l.search[1] === '/') {
29+
var decoded = l.search.slice(1).split('&').map(function (s) {
30+
return s.replace(/~and~/g, '&')
31+
}).join('?');
32+
window.history.replaceState(null, null,
33+
l.pathname.slice(0, -1) + decoded + l.hash
34+
);
35+
}
36+
}(window.location))
37+
</script>
38+
39+
<!-- GitHub OAuth redirect handler -->
40+
<script type="text/javascript">
3841
// Handle GitHub OAuth redirect for TradingGoose.github.io
39-
(function() {
42+
(function () {
4043
// No path adjustment needed since we're hosting at root domain
4144
// OAuth redirects should work correctly without path manipulation
4245
})();
43-
</script>
44-
45-
<!-- Monetization -->
46-
<meta name="monetag" content="aa7657d1e1fd4b0652f23bb7db3cd23e">
46+
</script>
47+
48+
<!-- Google AdSense -->
49+
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9651663494022087"
50+
crossorigin="anonymous"></script>
51+
52+
<!-- Google tag (gtag.js) Google Analytics -->
53+
<script async src="https://www.googletagmanager.com/gtag/js?id=G-HYXMNMH4WX"></script>
54+
<script>
55+
window.dataLayer = window.dataLayer || [];
56+
function gtag() { dataLayer.push(arguments); }
57+
gtag('js', new Date());
58+
59+
// Initial config without user_id
60+
gtag('config', 'G-HYXMNMH4WX', {
61+
send_page_view: false, // Prevent automatic pageview
62+
custom_map: {
63+
'dimension1': 'login_status',
64+
'dimension2': 'user_type'
65+
}
66+
});
67+
68+
// Function to track authenticated users
69+
window.trackAuthenticatedUser = function (userId, userType) {
70+
if (userId) {
71+
gtag('config', 'G-HYXMNMH4WX', {
72+
user_id: userId,
73+
user_properties: {
74+
user_type: userType || 'standard'
75+
}
76+
});
4777

48-
<!-- Google AdSense -->
49-
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9651663494022087"
50-
crossorigin="anonymous"></script>
78+
// Send custom pageview for authenticated users
79+
gtag('event', 'page_view', {
80+
login_status: 'logged_in',
81+
user_type: userType || 'standard'
82+
});
83+
}
84+
};
5185

52-
<!-- Google tag (gtag.js) Google Analytics -->
53-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-HYXMNMH4WX"></script>
54-
<script>
55-
window.dataLayer = window.dataLayer || [];
56-
function gtag(){dataLayer.push(arguments);}
57-
gtag('js', new Date());
86+
// Function to track anonymous pageviews
87+
window.trackAnonymousPageview = function () {
88+
gtag('event', 'page_view', {
89+
login_status: 'anonymous'
90+
});
91+
};
92+
</script>
5893

59-
gtag('config', 'G-HYXMNMH4WX');
60-
</script>
6194

95+
</head>
6296

63-
</head>
97+
<body>
98+
<div id="root"></div>
99+
<script type="module" src="/src/main.tsx"></script>
100+
</body>
64101

65-
<body>
66-
<div id="root"></div>
67-
<script type="module" src="/src/main.tsx"></script>
68-
</body>
69-
</html>
102+
</html>

src/components/AuthProvider.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
import { useEffect } from 'react';
2-
import { initializeAuth } from '@/lib/auth';
2+
import { initializeAuth, useAuth } from '@/lib/auth';
3+
4+
declare global {
5+
interface Window {
6+
trackAuthenticatedUser: (userId: string, userType?: string) => void;
7+
trackAnonymousPageview: () => void;
8+
}
9+
}
310

411
export function AuthProvider({ children }: { children: React.ReactNode }) {
12+
const { isAuthenticated, user } = useAuth();
13+
514
useEffect(() => {
615
// Initialize authentication when app starts
716
initializeAuth();
817
}, []);
918

19+
useEffect(() => {
20+
// Track user based on authentication status
21+
if (isAuthenticated && user?.id && window.trackAuthenticatedUser) {
22+
// Track authenticated user with their unique ID
23+
window.trackAuthenticatedUser(user.id, user.role || 'standard');
24+
} else if (!isAuthenticated && window.trackAnonymousPageview) {
25+
// Track anonymous pageview
26+
window.trackAnonymousPageview();
27+
}
28+
}, [isAuthenticated, user]);
29+
1030
return <>{children}</>;
1131
}

0 commit comments

Comments
 (0)