-
-
Notifications
You must be signed in to change notification settings - Fork 41
Analytics Integration & Modal Optimization #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| import { useCallback, useEffect, useState } from "react"; | ||
| import { AnimatePresence, motion } from "framer-motion"; | ||
| import Image from "next/image"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { Github, Loader, X } from "lucide-react"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
|
|
@@ -40,15 +39,29 @@ export default function GitHubModal({ onClose }: GitHubModalProps) { | |
| const [isValidating, setIsValidating] = useState(false); | ||
| const [error, setError] = useState(""); | ||
| const [profile, setProfile] = useState<GitHubProfile | null>(null); | ||
| const router = useRouter(); | ||
| const [loading, setLoading] = useState(false); | ||
|
|
||
| const redirectToProfilePage = async () => { | ||
| const redirectToProfilePage = () => { | ||
| if (!profile) return; | ||
| setLoading(true); | ||
| await router.push(`/${profile?.login}?ref=modal`); | ||
|
|
||
| // Get current search params and preserve them | ||
| const currentParams = new URLSearchParams(window.location.search); | ||
| currentParams.set('ref', 'modal'); | ||
|
|
||
| // Use window.location for instant navigation | ||
| window.location.href = `/${profile?.login}?${currentParams.toString()}`; | ||
| }; | ||
|
|
||
| // no need to setLoading(false) because navigation will replace this page | ||
| const redirectToProfilePageFromCard = () => { | ||
| if (!profile) return; | ||
|
|
||
| // Get current search params and preserve them | ||
| const currentParams = new URLSearchParams(window.location.search); | ||
| currentParams.set('ref', 'modelv2'); | ||
|
|
||
| // Use window.location for instant navigation | ||
| window.location.href = `/${profile?.login}?${currentParams.toString()}`; | ||
| }; | ||
| // Debounce the username input to prevent excessive API calls | ||
| const debouncedUsername = useDebounce(username, 500); | ||
|
Comment on lines
46
to
67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's code duplication between |
||
|
|
@@ -152,7 +165,8 @@ export default function GitHubModal({ onClose }: GitHubModalProps) { | |
| <motion.div | ||
| initial={{ opacity: 0, y: 10 }} | ||
| animate={{ opacity: 1, y: 0 }} | ||
| className="bg-gray-50 rounded-lg p-4 flex items-center gap-4" | ||
| onClick={redirectToProfilePageFromCard} | ||
| className="bg-gray-50 rounded-lg p-4 flex items-center gap-4 cursor-pointer hover:bg-gray-100 transition-colors" | ||
| > | ||
| <Image | ||
| src={profile.avatar_url} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,15 @@ import { parseStringPromise } from "xml2js"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const API_KEY = process.env.NEXT_PUBLIC_X_API_KEY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Utility function to detect provider from URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const detectProvider = (url: string): string => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const urlLower = url.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (urlLower.includes('medium.com')) return 'medium'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (urlLower.includes('instagram.com')) return 'instagram'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (urlLower.includes('huggingface.co')) return 'huggingface'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 'generic'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This While you're at it, you could improve this function by adding detection for Example update for if (urlLower.includes('devb.io')) return 'devb'; |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Fetch resource with Next.js caching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -228,29 +237,108 @@ export const getLinkedInProfileData = async ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * API to add user to Nocodb table for analytics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * API to add user to Supabase via edge function for analytics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const addUserToNocodb = async (user: Profile | null) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const addUserToSupabase = async (user: Profile | null, searchParams?: URLSearchParams) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!user) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = `https://app.nocodb.com/api/v2/tables/${process.env.NOCODB_TABLE_ID}/records`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const headers = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| accept: "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "xc-token": process.env.NOCODB_API_KEY || "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Content-Type": "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const supabaseUrl = process.env.SUPABASE_URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const supabaseAnonKey = process.env.SUPABASE_KEY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!supabaseUrl || !supabaseAnonKey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Supabase configuration missing"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = `${supabaseUrl}/functions/v1/devb-io`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Map user data to match Supabase function whitelist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mappedData: Record<string, string> = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: user.username, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| socials: user.social_accounts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "full name": user.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "devb profile": `https://devb.io/${user.username}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| github: `https://github.com/${user.username}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add query parameters if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (searchParams) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // UTM parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utmSource = searchParams.get('utm_source'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utmMedium = searchParams.get('utm_medium'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utmCampaign = searchParams.get('utm_campaign'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utmTerm = searchParams.get('utm_term'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const utmContent = searchParams.get('utm_content'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Referral parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ref = searchParams.get('ref'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add to mapped data if they exist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utmSource) mappedData['utm_source'] = utmSource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utmMedium) mappedData['utm_medium'] = utmMedium; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utmCampaign) mappedData['utm_campaign'] = utmCampaign; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utmTerm) mappedData['utm_term'] = utmTerm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (utmContent) mappedData['utm_content'] = utmContent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ref) mappedData['ref'] = ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+265
to
+281
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code for handling UTM parameters and
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Counter for generic URLs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let genericCounter = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add social accounts based on provider | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user.social_accounts?.forEach((account) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const provider = account.provider.toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If provider is generic, detect the actual platform | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const actualProvider = provider === "generic" ? detectProvider(account.url) : provider; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (actualProvider) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "linkedin": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData["Linkedin"] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "twitter": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData["twitter"] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "medium": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData["Medium"] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "instagram": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData["instagram"] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "huggingface": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Could add huggingface to whitelist if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "generic": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if it's a devb.io link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (account.url.includes("devb.io")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData["devb"] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For other generic URLs, number them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mappedData[`generic ${genericCounter}`] = account.url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| genericCounter++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const headers = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Content-Type": "application/json", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Authorization": `Bearer ${supabaseAnonKey}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await fetch(url, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(url, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: "POST", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: JSON.stringify(data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: JSON.stringify(mappedData), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error(`HTTP error! status: ${response.status}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await response.json(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log("User data sent to Supabase:", result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Error:", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error("Error sending data to Supabase:", error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
value &&check filters out empty strings (e.g., from?ref=), which might be unintentional as empty strings can be valid parameter values. Thetypeof value === 'string'check already handlesnullandundefined. Consider removingvalue &&to allow tracking of parameters with empty values.