/**
 * Get source identifier based on current pathname
 * Used for pixel loading and analytics tracking
 * 
 * @param pathname - Current window pathname (defaults to window.location.pathname)
 * @returns Source identifier string
 */
export function getSourceByPathname(pathname?: string): string {
  if (typeof window === "undefined") {
    return "unknown";
  }

  const currentPath = pathname ?? window.location.pathname;

  // Extract funnel ID from pathname
  // Expected format: /[funnelId] or /[funnelId]/[screenId]
  const segments = currentPath.split("/").filter(Boolean);
  
  if (segments.length > 0) {
    // Return first segment as funnel ID
    return segments[0];
  }

  return "home";
}
