@tryghost/referrer-parser 0.1.1 → 0.1.3
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.
- package/dist/index.d.ts +127 -29
- package/package.json +9 -10
- package/LICENSE +0 -21
- package/dist/lib/ReferrerParser.d.ts +0 -97
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* //
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Parse a referrer URL to get source, medium and hostname
|
|
3
|
+
*
|
|
4
|
+
* @param referrerUrl - URL of the referrer to parse
|
|
5
|
+
* @param options - Configuration options
|
|
6
|
+
* @param referrerSource - Optional source to override URL parameters
|
|
7
|
+
* @param referrerMedium - Optional medium to override URL parameters
|
|
8
|
+
* @returns Parsed referrer data with source, medium and URL
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Basic usage
|
|
12
|
+
* const result = parse('https://www.google.com/search?q=ghost+cms');
|
|
13
|
+
* // result: { referrerSource: 'Google', referrerMedium: 'search', referrerUrl: 'www.google.com' }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // With site configuration
|
|
17
|
+
* const result = parse('https://example.com/blog?utm_source=newsletter', {
|
|
18
|
+
* siteUrl: 'https://example.com'
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // With explicit source and medium
|
|
23
|
+
* const result = parse('https://example.com', {}, 'newsletter', 'email');
|
|
24
|
+
*/
|
|
25
|
+
export declare function parse(referrerUrl: string, options?: ParserOptions, referrerSource?: string, referrerMedium?: string): ReferrerData;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Configuration options for the parser
|
|
29
|
+
*/
|
|
30
|
+
export declare interface ParserOptions {
|
|
31
|
+
/** URL of the site for identifying internal traffic */
|
|
32
|
+
siteUrl?: string;
|
|
33
|
+
/** URL of the admin panel for identifying admin traffic */
|
|
34
|
+
adminUrl?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Interface for parsed referrer data
|
|
39
|
+
*/
|
|
40
|
+
export declare interface ReferrerData {
|
|
41
|
+
/** The identified source of the referral traffic */
|
|
42
|
+
referrerSource: string | null;
|
|
43
|
+
/** The identified medium of the referral traffic */
|
|
44
|
+
referrerMedium: string | null;
|
|
45
|
+
/** The hostname of the referral URL */
|
|
46
|
+
referrerUrl: string | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Parses referrer URLs to determine source and medium
|
|
51
|
+
*/
|
|
52
|
+
export declare class ReferrerParser {
|
|
53
|
+
private adminUrl;
|
|
54
|
+
private siteUrl;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new referrer parser instance
|
|
57
|
+
*
|
|
58
|
+
* @param options - Configuration options
|
|
59
|
+
*/
|
|
60
|
+
constructor(options?: ParserOptions);
|
|
61
|
+
/**
|
|
62
|
+
* Parse a referrer URL to get source, medium and hostname
|
|
63
|
+
*
|
|
64
|
+
* @param referrerUrlStr - URL of the referrer
|
|
65
|
+
* @param referrerSource - Source of the referrer
|
|
66
|
+
* @param referrerMedium - Medium of the referrer
|
|
67
|
+
* @returns Parsed referrer data with source, medium and URL. Internal referrers return null values.
|
|
68
|
+
*/
|
|
69
|
+
parse(referrerUrlStr: string, referrerSource?: string, referrerMedium?: string): ReferrerData;
|
|
70
|
+
/**
|
|
71
|
+
* Fetches referrer data from known external URLs
|
|
72
|
+
*
|
|
73
|
+
* @param url - The URL to match against known referrers
|
|
74
|
+
* @returns Matched referrer data or null if not found
|
|
75
|
+
*/
|
|
76
|
+
getDataFromUrl(url: URL | null): ReferrerSourceData | null;
|
|
77
|
+
/**
|
|
78
|
+
* Return URL object for provided URL string
|
|
79
|
+
*
|
|
80
|
+
* @param url - URL string to parse
|
|
81
|
+
* @returns Parsed URL object or null if invalid
|
|
82
|
+
*/
|
|
83
|
+
getUrlFromStr(url: string): URL | null;
|
|
84
|
+
/**
|
|
85
|
+
* Determine whether the provided URL is a link to the site
|
|
86
|
+
*
|
|
87
|
+
* @param url - URL to check
|
|
88
|
+
* @returns True if the URL belongs to the configured site
|
|
89
|
+
*/
|
|
90
|
+
isSiteDomain(url: URL | null): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Determine whether referrer is a Ghost newsletter
|
|
93
|
+
*
|
|
94
|
+
* @param deps - Input parameters
|
|
95
|
+
* @returns True if the referrer is a Ghost newsletter
|
|
96
|
+
*/
|
|
97
|
+
isGhostNewsletter({ referrerSource }: {
|
|
98
|
+
referrerSource: string | null;
|
|
99
|
+
}): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Determine whether referrer is a Ghost.org URL
|
|
102
|
+
*
|
|
103
|
+
* @param referrerUrl - The referrer URL to check
|
|
104
|
+
* @returns True if the referrer is from Ghost.org
|
|
105
|
+
*/
|
|
106
|
+
isGhostOrgUrl(referrerUrl: URL | null): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Determine whether referrer is Ghost Explore
|
|
109
|
+
*
|
|
110
|
+
* @param deps - Input parameters
|
|
111
|
+
* @returns True if the referrer is from Ghost Explore
|
|
112
|
+
*/
|
|
113
|
+
isGhostExploreRef({ referrerUrl, referrerSource }: {
|
|
114
|
+
referrerUrl: URL | null;
|
|
115
|
+
referrerSource?: string | null;
|
|
116
|
+
}): boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Interface for referrer source data
|
|
121
|
+
*/
|
|
122
|
+
declare interface ReferrerSourceData {
|
|
123
|
+
source: string;
|
|
124
|
+
medium: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/referrer-parser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Simple library for parsing referrer URLs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/index.js",
|
|
12
|
-
"require": "./dist/index.cjs"
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
@@ -50,22 +50,21 @@
|
|
|
50
50
|
"@types/node": "^22.0.0",
|
|
51
51
|
"@types/should": "^13.0.0",
|
|
52
52
|
"@types/sinon": "^17.0.3",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
55
|
-
"@vitest/coverage-v8": "^
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
54
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
55
|
+
"@vitest/coverage-v8": "^3.0.0",
|
|
56
56
|
"eslint": "^8.52.0",
|
|
57
57
|
"should": "13.2.3",
|
|
58
58
|
"sinon": "20.0.0",
|
|
59
59
|
"typescript": "5.4.3",
|
|
60
60
|
"vite": "^6.0.0",
|
|
61
|
-
"vite-plugin-dts": "^
|
|
62
|
-
"vitest": "^
|
|
61
|
+
"vite-plugin-dts": "^4.0.0",
|
|
62
|
+
"vitest": "^3.0.0"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=16.0.0"
|
|
66
66
|
},
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
|
-
}
|
|
70
|
-
"gitHead": "42a1892311fd717a5fb87a07b96197455100d3b8"
|
|
69
|
+
}
|
|
71
70
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013-2025 Ghost Foundation
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
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
|
-
* @param referrerSource - Source of the referrer
|
|
45
|
-
* @param referrerMedium - Medium of the referrer
|
|
46
|
-
* @returns Parsed referrer data with source, medium and URL. Internal referrers return null values.
|
|
47
|
-
*/
|
|
48
|
-
parse(referrerUrlStr: string, referrerSource?: string, referrerMedium?: string): ReferrerData;
|
|
49
|
-
/**
|
|
50
|
-
* Fetches referrer data from known external URLs
|
|
51
|
-
*
|
|
52
|
-
* @param url - The URL to match against known referrers
|
|
53
|
-
* @returns Matched referrer data or null if not found
|
|
54
|
-
*/
|
|
55
|
-
getDataFromUrl(url: URL | null): ReferrerSourceData | null;
|
|
56
|
-
/**
|
|
57
|
-
* Return URL object for provided URL string
|
|
58
|
-
*
|
|
59
|
-
* @param url - URL string to parse
|
|
60
|
-
* @returns Parsed URL object or null if invalid
|
|
61
|
-
*/
|
|
62
|
-
getUrlFromStr(url: string): URL | null;
|
|
63
|
-
/**
|
|
64
|
-
* Determine whether the provided URL is a link to the site
|
|
65
|
-
*
|
|
66
|
-
* @param url - URL to check
|
|
67
|
-
* @returns True if the URL belongs to the configured site
|
|
68
|
-
*/
|
|
69
|
-
isSiteDomain(url: URL | null): boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Determine whether referrer is a Ghost newsletter
|
|
72
|
-
*
|
|
73
|
-
* @param deps - Input parameters
|
|
74
|
-
* @returns True if the referrer is a Ghost newsletter
|
|
75
|
-
*/
|
|
76
|
-
isGhostNewsletter({ referrerSource }: {
|
|
77
|
-
referrerSource: string | null;
|
|
78
|
-
}): boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Determine whether referrer is a Ghost.org URL
|
|
81
|
-
*
|
|
82
|
-
* @param referrerUrl - The referrer URL to check
|
|
83
|
-
* @returns True if the referrer is from Ghost.org
|
|
84
|
-
*/
|
|
85
|
-
isGhostOrgUrl(referrerUrl: URL | null): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Determine whether referrer is Ghost Explore
|
|
88
|
-
*
|
|
89
|
-
* @param deps - Input parameters
|
|
90
|
-
* @returns True if the referrer is from Ghost Explore
|
|
91
|
-
*/
|
|
92
|
-
isGhostExploreRef({ referrerUrl, referrerSource }: {
|
|
93
|
-
referrerUrl: URL | null;
|
|
94
|
-
referrerSource?: string | null;
|
|
95
|
-
}): boolean;
|
|
96
|
-
}
|
|
97
|
-
export {};
|