@tryghost/referrer-parser 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../lib/ReferrerParser.ts","../index.ts"],"sourcesContent":["/**\n * Interface for parsed referrer data\n */\nexport interface ReferrerData {\n /** The identified source of the referral traffic */\n referrerSource: string | null;\n /** The identified medium of the referral traffic */\n referrerMedium: string | null;\n /** The hostname of the referral URL */\n referrerUrl: string | null;\n}\n\n/**\n * Configuration options for the parser\n */\nexport interface ParserOptions {\n /** URL of the site for identifying internal traffic */\n siteUrl?: string;\n /** URL of the admin panel for identifying admin traffic */\n adminUrl?: string;\n}\n\n/**\n * Interface for referrer source data\n */\ninterface ReferrerSourceData {\n source: string;\n medium: string;\n}\n\n// Import known referrers data\nimport knownReferrers from './referrers.json';\n\n/**\n * Parses referrer URLs to determine source and medium\n */\nexport class ReferrerParser {\n private adminUrl: URL | null;\n private siteUrl: URL | null;\n\n /**\n * Creates a new referrer parser instance\n * \n * @param options - Configuration options\n */\n constructor(options: ParserOptions = {}) {\n this.adminUrl = this.getUrlFromStr(options.adminUrl || '');\n this.siteUrl = this.getUrlFromStr(options.siteUrl || '');\n }\n\n /**\n * Parse a referrer URL to get source, medium and hostname\n * \n * @param referrerUrlStr - URL of the referrer\n * @returns Parsed referrer data with source, medium and URL\n */\n parse(referrerUrlStr: string): ReferrerData {\n if (!referrerUrlStr) {\n return {\n referrerSource: 'Direct',\n referrerMedium: null,\n referrerUrl: null\n };\n }\n\n const referrerUrl = this.getUrlFromStr(referrerUrlStr);\n if (!referrerUrl) {\n return {\n referrerSource: 'Direct',\n referrerMedium: null,\n referrerUrl: null\n };\n }\n\n // Skip Stripe checkout URLs\n if (referrerUrl.hostname === 'checkout.stripe.com') {\n return {\n referrerSource: 'Direct',\n referrerMedium: null,\n referrerUrl: null\n };\n }\n\n // Check for source/medium in query parameters\n const urlParams = new URLSearchParams(referrerUrl.search);\n const referrerSource = urlParams.get('utm_source') || urlParams.get('source') || null;\n const referrerMedium = urlParams.get('utm_medium') || urlParams.get('medium') || null;\n\n // If referrer is Ghost Explore\n if (this.isGhostExploreRef({referrerUrl, referrerSource})) {\n return {\n referrerSource: 'Ghost Explore',\n referrerMedium: 'Ghost Network',\n referrerUrl: referrerUrl?.hostname ?? null\n };\n }\n\n // If referrer is Ghost.org\n if (this.isGhostOrgUrl(referrerUrl)) {\n return {\n referrerSource: 'Ghost.org',\n referrerMedium: 'Ghost Network',\n referrerUrl: referrerUrl?.hostname\n };\n }\n\n // Check for Ghost Newsletter\n if (this.isGhostNewsletter({referrerSource})) {\n return {\n referrerSource: referrerSource!.replace(/-newsletter$/, ' newsletter'),\n referrerMedium: 'Email',\n referrerUrl: referrerUrl?.hostname ?? null\n };\n }\n\n // If referrer source is available from parameters\n if (referrerSource) {\n const urlData = this.getDataFromUrl(referrerUrl);\n const knownSource = Object.values(knownReferrers as Record<string, ReferrerSourceData>).find(referrer => \n referrer.source.toLowerCase() === referrerSource.toLowerCase());\n \n return {\n referrerSource: knownSource?.source || referrerSource,\n referrerMedium: knownSource?.medium || referrerMedium || urlData?.medium || null,\n referrerUrl: referrerUrl?.hostname ?? null\n };\n }\n\n // If referrer is known external URL\n if (!this.isSiteDomain(referrerUrl)) {\n const urlData = this.getDataFromUrl(referrerUrl);\n\n // Use known source/medium if available\n if (urlData) {\n return {\n referrerSource: urlData?.source ?? null,\n referrerMedium: urlData?.medium ?? null,\n referrerUrl: referrerUrl?.hostname ?? null\n };\n }\n \n // Use the hostname as a source\n return {\n referrerSource: referrerUrl?.hostname ?? null,\n referrerMedium: null,\n referrerUrl: referrerUrl?.hostname ?? null\n };\n }\n\n return {\n referrerSource: 'Direct',\n referrerMedium: null,\n referrerUrl: null\n };\n }\n\n /**\n * Fetches referrer data from known external URLs\n * \n * @param url - The URL to match against known referrers\n * @returns Matched referrer data or null if not found\n */\n getDataFromUrl(url: URL | null): ReferrerSourceData | null {\n // Handle null url case\n if (!url) {\n return null;\n }\n\n // Allow matching both \"google.ac/products\" and \"google.ac\" as a source\n const urlHostPath = url.hostname + url.pathname;\n const urlDataKey = Object.keys(knownReferrers as Record<string, ReferrerSourceData>).sort((a, b) => {\n // The longer key has higher priority so google.ac/products is selected before google.ac\n return b.length - a.length;\n }).find((source) => {\n return urlHostPath.startsWith(source);\n });\n\n return urlDataKey ? (knownReferrers as Record<string, ReferrerSourceData>)[urlDataKey] : null;\n }\n\n /**\n * Return URL object for provided URL string\n * \n * @param url - URL string to parse\n * @returns Parsed URL object or null if invalid\n */\n getUrlFromStr(url: string): URL | null {\n if (!url) {\n return null;\n }\n \n try {\n return new URL(url);\n } catch (e) {\n return null;\n }\n }\n\n /**\n * Determine whether the provided URL is a link to the site\n * \n * @param url - URL to check\n * @returns True if the URL belongs to the configured site\n */\n isSiteDomain(url: URL | null): boolean {\n try {\n // If we don't have siteUrl configured, we can't detect internal traffic\n if (!this.siteUrl) {\n return false;\n }\n\n if (!url) {\n return false;\n }\n\n if (this.siteUrl.hostname === url.hostname) {\n if (url.pathname.startsWith(this.siteUrl.pathname)) {\n return true;\n }\n return false;\n }\n return false;\n } catch (e) {\n return false;\n }\n }\n\n /**\n * Determine whether referrer is a Ghost newsletter\n * \n * @param deps - Input parameters\n * @returns True if the referrer is a Ghost newsletter\n */\n isGhostNewsletter({referrerSource}: {referrerSource: string | null}): boolean {\n if (!referrerSource) {\n return false;\n }\n // if referrer source ends with -newsletter\n return referrerSource.endsWith('-newsletter');\n }\n\n /**\n * Determine whether referrer is a Ghost.org URL\n * \n * @param referrerUrl - The referrer URL to check\n * @returns True if the referrer is from Ghost.org\n */\n isGhostOrgUrl(referrerUrl: URL | null): boolean {\n if (!referrerUrl) {\n return false;\n }\n return referrerUrl.hostname === 'ghost.org';\n }\n\n /**\n * Determine whether referrer is Ghost Explore\n * \n * @param deps - Input parameters\n * @returns True if the referrer is from Ghost Explore\n */\n isGhostExploreRef({referrerUrl, referrerSource}: {referrerUrl: URL | null, referrerSource?: string | null}): boolean {\n // Always check for ghost-explore source param\n if (referrerSource === 'ghost-explore') {\n return true;\n }\n\n if (!referrerUrl) {\n return false;\n }\n\n // Check domain for explore.ghost.io and try.ghost.org/explore\n if (referrerUrl.hostname === 'explore.ghost.io') {\n return true;\n }\n\n if (referrerUrl.hostname === 'try.ghost.org' && referrerUrl.pathname.startsWith('/explore')) {\n return true;\n }\n\n return false;\n }\n} ","import { ReferrerParser } from './lib/ReferrerParser';\nimport type { ReferrerData, ParserOptions } from './lib/ReferrerParser';\n\n/**\n * Parse a referrer URL to get source, medium and hostname\n * \n * @param referrerUrl - URL of the referrer to parse\n * @param options - Configuration options\n * @returns Parsed referrer data with source, medium and URL\n * \n * @example\n * // Basic usage\n * const result = parse('https://www.google.com/search?q=ghost+cms');\n * // result: { referrerSource: 'Google', referrerMedium: 'search', referrerUrl: 'www.google.com' }\n * \n * @example\n * // With site configuration\n * const result = parse('https://example.com/blog?utm_source=newsletter', {\n * siteUrl: 'https://example.com'\n * });\n */\nfunction parse(referrerUrl: string, options: ParserOptions = {}): ReferrerData {\n const parser = new ReferrerParser(options);\n return parser.parse(referrerUrl);\n}\n\nexport {\n parse,\n ReferrerParser\n};\n\nexport type {\n ReferrerData,\n ParserOptions\n}; "],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
2
+ * Interface for parsed referrer data
3
+ */
4
+ export interface ReferrerData {
5
+ /** The identified source of the referral traffic */
6
+ referrerSource: string | null;
7
+ /** The identified medium of the referral traffic */
8
+ referrerMedium: string | null;
9
+ /** The hostname of the referral URL */
10
+ referrerUrl: string | null;
11
+ }
12
+ /**
13
+ * Configuration options for the parser
14
+ */
15
+ export interface ParserOptions {
16
+ /** URL of the site for identifying internal traffic */
17
+ siteUrl?: string;
18
+ /** URL of the admin panel for identifying admin traffic */
19
+ adminUrl?: string;
20
+ }
21
+ /**
22
+ * Interface for referrer source data
23
+ */
24
+ interface ReferrerSourceData {
25
+ source: string;
26
+ medium: string;
27
+ }
28
+ /**
29
+ * Parses referrer URLs to determine source and medium
30
+ */
31
+ export declare class ReferrerParser {
32
+ private adminUrl;
33
+ private siteUrl;
34
+ /**
35
+ * Creates a new referrer parser instance
36
+ *
37
+ * @param options - Configuration options
38
+ */
39
+ constructor(options?: ParserOptions);
40
+ /**
41
+ * Parse a referrer URL to get source, medium and hostname
42
+ *
43
+ * @param referrerUrlStr - URL of the referrer
44
+ * @returns Parsed referrer data with source, medium and URL
45
+ */
46
+ parse(referrerUrlStr: string): ReferrerData;
47
+ /**
48
+ * Fetches referrer data from known external URLs
49
+ *
50
+ * @param url - The URL to match against known referrers
51
+ * @returns Matched referrer data or null if not found
52
+ */
53
+ getDataFromUrl(url: URL | null): ReferrerSourceData | null;
54
+ /**
55
+ * Return URL object for provided URL string
56
+ *
57
+ * @param url - URL string to parse
58
+ * @returns Parsed URL object or null if invalid
59
+ */
60
+ getUrlFromStr(url: string): URL | null;
61
+ /**
62
+ * Determine whether the provided URL is a link to the site
63
+ *
64
+ * @param url - URL to check
65
+ * @returns True if the URL belongs to the configured site
66
+ */
67
+ isSiteDomain(url: URL | null): boolean;
68
+ /**
69
+ * Determine whether referrer is a Ghost newsletter
70
+ *
71
+ * @param deps - Input parameters
72
+ * @returns True if the referrer is a Ghost newsletter
73
+ */
74
+ isGhostNewsletter({ referrerSource }: {
75
+ referrerSource: string | null;
76
+ }): boolean;
77
+ /**
78
+ * Determine whether referrer is a Ghost.org URL
79
+ *
80
+ * @param referrerUrl - The referrer URL to check
81
+ * @returns True if the referrer is from Ghost.org
82
+ */
83
+ isGhostOrgUrl(referrerUrl: URL | null): boolean;
84
+ /**
85
+ * Determine whether referrer is Ghost Explore
86
+ *
87
+ * @param deps - Input parameters
88
+ * @returns True if the referrer is from Ghost Explore
89
+ */
90
+ isGhostExploreRef({ referrerUrl, referrerSource }: {
91
+ referrerUrl: URL | null;
92
+ referrerSource?: string | null;
93
+ }): boolean;
94
+ }
95
+ export {};