UNPKG

@technoapple/ga4

Version:

TypeScript Node.js library to support GA4 analytics.

38 lines (36 loc) 894 B
export interface ParsedUrl { href: string; protocol: string; hostname: string; port: string; pathname: string; search: string; hash: string; origin: string; } export function parseUrl(url: string): ParsedUrl { try { const parsed = new URL(url, location.href); return { href: parsed.href, protocol: parsed.protocol, hostname: parsed.hostname, port: parsed.port, pathname: parsed.pathname, search: parsed.search, hash: parsed.hash, origin: parsed.origin, }; } catch { return { href: url, protocol: '', hostname: '', port: '', pathname: url, search: '', hash: '', origin: '', }; } }