@siteline/core 1.0.0
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/CHANGELOG.md +18 -0
- package/README.md +235 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/siteline.d.ts +14 -0
- package/dist/siteline.d.ts.map +1 -0
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @siteline/core
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
Initial release
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- Core Client tracking SDK
|
|
10
|
+
- TypeScript support with full type definitions
|
|
11
|
+
- Automatic data sanitization and validation
|
|
12
|
+
- HTTPS-only enforcement
|
|
13
|
+
- Edge runtime support (Cloudflare Workers, Vercel Edge, Deno)
|
|
14
|
+
- Node.js 18+ support
|
|
15
|
+
- Zero runtime dependencies
|
|
16
|
+
- ~1.6KB minified + gzipped
|
|
17
|
+
- Configurable endpoint and debug mode
|
|
18
|
+
- 5-second request timeout protection
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# @siteline/core
|
|
2
|
+
|
|
3
|
+
Core tracking SDK for Client - Agent Analytics platform for tracking how AI agents, bots, and crawlers interact with your website.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **AI Agent Tracking**: Track bots from OpenAI, Google, Anthropic, Perplexity, and more
|
|
8
|
+
- **Lightweight**: ~1.6KB minified + gzipped
|
|
9
|
+
- **Type-safe**: Full TypeScript support with exported types
|
|
10
|
+
- **Zero dependencies**: No external runtime dependencies
|
|
11
|
+
- **Automatic sanitization**: Request data validation and size limits
|
|
12
|
+
- **HTTPS enforced**: Secure-only data transmission
|
|
13
|
+
- **Configurable**: Custom endpoints and debug mode
|
|
14
|
+
- **Edge-ready**: Works in edge runtimes, Node.js, and browsers
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @siteline/core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
yarn add @siteline/core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add @siteline/core
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Client } from '@siteline/core';
|
|
34
|
+
|
|
35
|
+
// Initialize the tracker
|
|
36
|
+
const siteline = new Client({
|
|
37
|
+
websiteKey: 'siteline_secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
38
|
+
debug: true, // Optional: enable debug logs
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Track a pageview
|
|
42
|
+
siteline.track({
|
|
43
|
+
url: '/home',
|
|
44
|
+
method: 'GET',
|
|
45
|
+
status: 200,
|
|
46
|
+
duration: 45,
|
|
47
|
+
userAgent: 'Mozilla/5.0...',
|
|
48
|
+
ref: 'https://google.com',
|
|
49
|
+
ip: '192.168.1.1',
|
|
50
|
+
sdk: '@siteline/core',
|
|
51
|
+
sdk_version: '1.0.0',
|
|
52
|
+
integration_type: 'custom',
|
|
53
|
+
websiteKey: 'siteline_secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxx',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## API Reference
|
|
58
|
+
|
|
59
|
+
### `new Client(config: SitelineConfig)`
|
|
60
|
+
|
|
61
|
+
Creates a new Client tracker instance.
|
|
62
|
+
|
|
63
|
+
#### Configuration Options
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
type SitelineConfig = {
|
|
67
|
+
websiteKey: string; // Required: Your Client website key (format: siteline_secret_<32 hex chars>)
|
|
68
|
+
endpoint?: string; // Optional: Custom API endpoint (default: https://api.siteline.ai/v1/intake/pageview)
|
|
69
|
+
debug?: boolean; // Optional: Enable debug logging (default: false)
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Example:**
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const siteline = new Client({
|
|
77
|
+
websiteKey: 'siteline_secret_abc123...',
|
|
78
|
+
endpoint: 'https://custom-endpoint.example.com/track', // Optional
|
|
79
|
+
debug: process.env.NODE_ENV === 'development', // Optional
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `siteline.track(data: PageviewData)`
|
|
84
|
+
|
|
85
|
+
Tracks a pageview event. Data is automatically sanitized and sent asynchronously.
|
|
86
|
+
|
|
87
|
+
#### PageviewData Type
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
type PageviewData = {
|
|
91
|
+
websiteKey: string; // Your Client website key
|
|
92
|
+
sdk: string; // SDK identifier (e.g., '@siteline/core')
|
|
93
|
+
sdk_version: string; // SDK version (e.g., '1.0.0')
|
|
94
|
+
integration_type: string; // Integration type (e.g., 'nextjs', 'express', 'custom')
|
|
95
|
+
|
|
96
|
+
// Request data
|
|
97
|
+
url: string; // Request URL path (max 2048 chars)
|
|
98
|
+
method: string; // HTTP method (max 10 chars, uppercased)
|
|
99
|
+
userAgent: string | null; // User-Agent header (max 512 chars)
|
|
100
|
+
ref: string | null; // Referer header (max 2048 chars)
|
|
101
|
+
ip: string | null; // Client IP address (max 45 chars for IPv6)
|
|
102
|
+
|
|
103
|
+
// Response data
|
|
104
|
+
status: number; // HTTP status code (0-999)
|
|
105
|
+
duration: number; // Request duration in ms (0-300000)
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Example:**
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
siteline.track({
|
|
113
|
+
websiteKey: 'siteline_secret_abc123...',
|
|
114
|
+
sdk: '@siteline/core',
|
|
115
|
+
sdk_version: '1.0.0',
|
|
116
|
+
integration_type: 'custom',
|
|
117
|
+
url: '/api/users',
|
|
118
|
+
method: 'GET',
|
|
119
|
+
status: 200,
|
|
120
|
+
duration: 125,
|
|
121
|
+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...',
|
|
122
|
+
ref: 'https://example.com/home',
|
|
123
|
+
ip: '203.0.113.42',
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Data Sanitization
|
|
128
|
+
|
|
129
|
+
All tracked data is automatically sanitized to ensure security and data integrity:
|
|
130
|
+
|
|
131
|
+
- **URL**: Truncated to 2048 characters
|
|
132
|
+
- **Method**: Uppercased, truncated to 10 characters
|
|
133
|
+
- **Status**: Clamped to 0-999 range
|
|
134
|
+
- **Duration**: Clamped to 0-300000ms (5 minutes)
|
|
135
|
+
- **User-Agent**: Truncated to 512 characters
|
|
136
|
+
- **Referrer**: Truncated to 2048 characters
|
|
137
|
+
- **IP Address**: Truncated to 45 characters (IPv6 compatible)
|
|
138
|
+
- **SDK/Integration**: Truncated to safe limits
|
|
139
|
+
|
|
140
|
+
## Error Handling
|
|
141
|
+
|
|
142
|
+
The SDK handles errors gracefully:
|
|
143
|
+
|
|
144
|
+
- **Invalid website key format**: Throws error during initialization
|
|
145
|
+
- **Non-HTTPS endpoint**: Throws error during initialization
|
|
146
|
+
- **Network errors**: Silently caught, logged in debug mode
|
|
147
|
+
- **Timeout errors**: Request aborted after 5 seconds
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
try {
|
|
151
|
+
const tracker = new Client({
|
|
152
|
+
websiteKey: 'invalid-key', // Throws error
|
|
153
|
+
});
|
|
154
|
+
} catch (error) {
|
|
155
|
+
console.error(error); // [Client] Invalid websiteKey format...
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Debug Mode
|
|
160
|
+
|
|
161
|
+
Enable debug logging to troubleshoot integration issues:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const tracker = new Client({
|
|
165
|
+
websiteKey: 'siteline_secret_abc123...',
|
|
166
|
+
debug: true,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
siteline.track({...});
|
|
170
|
+
// Console output:
|
|
171
|
+
// [Client] Client initialized { endpoint: 'https://api.siteline.ai/v1/intake/pageview' }
|
|
172
|
+
// [Client] Tracked: /home
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Environment Compatibility
|
|
176
|
+
|
|
177
|
+
- **Node.js**: >=18.0.0
|
|
178
|
+
- **Edge Runtimes**: Cloudflare Workers, Vercel Edge, Deno
|
|
179
|
+
- **Browsers**: Modern browsers with Fetch API support
|
|
180
|
+
- **TypeScript**: Full type safety with exported types
|
|
181
|
+
|
|
182
|
+
## Security
|
|
183
|
+
|
|
184
|
+
- **HTTPS Only**: All data transmission over encrypted connections
|
|
185
|
+
- **No PII Storage**: IP addresses and user agents are optional
|
|
186
|
+
- **Input Validation**: All inputs sanitized and validated
|
|
187
|
+
- **Timeout Protection**: 5-second request timeout
|
|
188
|
+
- **No Eval**: No use of `eval()` or similar unsafe functions
|
|
189
|
+
|
|
190
|
+
## Framework Integration
|
|
191
|
+
|
|
192
|
+
While `@siteline/core` can be used standalone, we provide official integrations:
|
|
193
|
+
|
|
194
|
+
- **[@siteline/nextjs](https://www.npmjs.com/package/@siteline/nextjs)**: Next.js middleware integration
|
|
195
|
+
|
|
196
|
+
## TypeScript Usage
|
|
197
|
+
|
|
198
|
+
All types are exported for use in your application:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { Client, type SitelineConfig, type PageviewData } from '@siteline/core';
|
|
202
|
+
|
|
203
|
+
const config: SitelineConfig = {
|
|
204
|
+
websiteKey: 'siteline_secret_abc123...',
|
|
205
|
+
debug: true,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const tracker = new Client(config);
|
|
209
|
+
|
|
210
|
+
const data: PageviewData = {
|
|
211
|
+
websiteKey: config.websiteKey,
|
|
212
|
+
sdk: '@siteline/core',
|
|
213
|
+
sdk_version: '1.0.0',
|
|
214
|
+
integration_type: 'custom',
|
|
215
|
+
url: '/api/endpoint',
|
|
216
|
+
method: 'POST',
|
|
217
|
+
status: 201,
|
|
218
|
+
duration: 89,
|
|
219
|
+
userAgent: null,
|
|
220
|
+
ref: null,
|
|
221
|
+
ip: null,
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
siteline.track(data);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
MIT
|
|
230
|
+
|
|
231
|
+
## Support
|
|
232
|
+
|
|
233
|
+
- **GitHub Issues**: [github.com/siteline-ai/siteline-sdk-js/issues](https://github.com/siteline-ai/siteline-sdk-js/issues)
|
|
234
|
+
- **Documentation**: [docs.gptrends.io/agent-analytics](https://docs.gptrends.io/agent-analytics)
|
|
235
|
+
- **Repository**: [github.com/siteline-ai/siteline-sdk-js](https://github.com/siteline-ai/siteline-sdk-js)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const DEFAULT_ENDPOINT = "https://siteline.ai/v1/intake/pageview";
|
|
2
|
+
export declare const DEFAULT_SDK_NAME = "@siteline/core";
|
|
3
|
+
export declare const DEFAULT_SDK_VERSION = "1.0.0";
|
|
4
|
+
export declare const DEFAULT_INTEGRATION_TYPE = "custom";
|
|
5
|
+
export declare const WEBSITEKEY_PATTERN: RegExp;
|
|
6
|
+
export declare const LIMITS: {
|
|
7
|
+
readonly URL_MAX_LENGTH: 2048;
|
|
8
|
+
readonly METHOD_MAX_LENGTH: 10;
|
|
9
|
+
readonly USER_AGENT_MAX_LENGTH: 512;
|
|
10
|
+
readonly REF_MAX_LENGTH: 2048;
|
|
11
|
+
readonly IP_MAX_LENGTH: 45;
|
|
12
|
+
readonly INTEGRATION_TYPE_MAX_LENGTH: 50;
|
|
13
|
+
readonly SDK_MAX_LENGTH: 50;
|
|
14
|
+
readonly SDK_VERSION_MAX_LENGTH: 20;
|
|
15
|
+
readonly STATUS_MIN: 0;
|
|
16
|
+
readonly STATUS_MAX: 999;
|
|
17
|
+
readonly DURATION_MIN: 0;
|
|
18
|
+
readonly DURATION_MAX: 300000;
|
|
19
|
+
};
|
|
20
|
+
export declare const TIMEOUT_MS = 5000;
|
|
21
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,2CAA2C,CAAC;AACzE,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AACjD,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAC3C,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAEjD,eAAO,MAAM,kBAAkB,QAAmC,CAAC;AAEnE,eAAO,MAAM,MAAM;;;;;;;;;;;;;CAaT,CAAC;AAEX,eAAO,MAAM,UAAU,OAAO,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SitelineError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class SitelineValidationError extends SitelineError {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class SitelineTransportError extends SitelineError {
|
|
8
|
+
constructor(message: string);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,aAAa;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,sBAAuB,SAAQ,aAAa;gBAC3C,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";class e extends Error{constructor(e){super(e),this.name="SitelineError"}}class t extends e{constructor(e){super(e),this.name="SitelineValidationError"}}const i=/^siteline_secret_[a-f0-9]{32}$/;exports.Siteline=class{constructor(e){if(!e.websiteKey?.match(i))throw new t("Invalid websiteKey format. Expected: siteline_secret_<32 hex chars>");if(this.key=e.websiteKey,this.endpoint=e.endpoint||"https://siteline.ai/v1/intake/pageview",this.debug=e.debug||!1,this.sdk=e.sdk||"@siteline/core",this.sdkVersion=e.sdkVersion||"1.0.0",this.integrationType=e.integrationType||"custom",!this.endpoint.startsWith("https://"))throw new t("Endpoint must use HTTPS");this.debug&&console.log("[Siteline] Siteline initialized")}track(e){const t=this.sanitize(e);this.send(t).catch(e=>{this.debug&&console.error("[Siteline] Track failed:",e.message)})}sanitize(e){return{websiteKey:this.key,url:(e.url+"").slice(0,2048),method:(e.method+"").toUpperCase().slice(0,10),status:Math.max(0,Math.min(999,Number(e.status)||0)),duration:Math.max(0,Math.min(3e5,Number(e.duration)||0)),userAgent:e.userAgent?(e.userAgent+"").slice(0,512):null,ref:e.ref?(e.ref+"").slice(0,2048):null,ip:e.ip?(e.ip+"").slice(0,45):null,integration_type:this.integrationType.slice(0,50),sdk:this.sdk.slice(0,50),sdk_version:this.sdkVersion.slice(0,20)}}async send(e){const t=new AbortController,i=setTimeout(()=>t.abort(),5e3);try{const i=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","User-Agent":`${this.sdk}/${this.sdkVersion}`},body:JSON.stringify(e),signal:t.signal});this.debug&&(i.ok?console.log("[Siteline] Tracked:",e.url):console.error("[Siteline] HTTP error:",i.status))}catch(e){this.debug&&console.error("[Siteline] Network error:",e.message)}finally{clearTimeout(i)}}},exports.SitelineError=e,exports.SitelineTransportError=class extends e{constructor(e){super(e),this.name="SitelineTransportError"}},exports.SitelineValidationError=t;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/errors.ts","../src/constants.ts","../src/siteline.ts"],"sourcesContent":[null,null,null],"names":["SitelineError","Error","constructor","message","super","this","name","SitelineValidationError","WEBSITEKEY_PATTERN","config","websiteKey","match","key","endpoint","debug","sdk","sdkVersion","integrationType","startsWith","console","log","track","data","sanitized","sanitize","send","catch","err","error","url","String","slice","method","toUpperCase","status","Math","max","min","Number","duration","userAgent","ref","ip","integration_type","sdk_version","controller","AbortController","timeout","setTimeout","abort","res","fetch","headers","body","JSON","stringify","signal","ok","clearTimeout"],"mappings":"aAAM,MAAOA,UAAsBC,MACjC,WAAAC,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,eACd,EAGI,MAAOC,UAAgCP,EAC3C,WAAAE,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,yBACd,ECXK,MAKME,EAAqB,wDCehC,WAAAN,CAAYO,GACV,IAAKA,EAAOC,YAAYC,MAAMH,GAC5B,MAAM,IAAID,EACR,uEAWJ,GAPAF,KAAKO,IAAMH,EAAOC,WAClBL,KAAKQ,SAAWJ,EAAOI,UD5BK,yCC6B5BR,KAAKS,MAAQL,EAAOK,QAAS,EAC7BT,KAAKU,IAAMN,EAAOM,KD7BU,iBC8B5BV,KAAKW,WAAaP,EAAOO,YD7BM,QC8B/BX,KAAKY,gBAAkBR,EAAOQ,iBD7BM,UC+B/BZ,KAAKQ,SAASK,WAAW,YAC5B,MAAM,IAAIX,EAAwB,2BAGhCF,KAAKS,OACPK,QAAQC,IAAI,kCAEhB,CAEA,KAAAC,CAAMC,GACJ,MAAMC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BAA0BsB,EAAIhB,QAGlD,CAAE,MAAOP,GACHtB,KAAKS,OAEPK,QAAQS,MAAM,4BADAD,EACmCxB,QAErD,SACEuD,aAAaX,EACf,CACF,0DFrFI,cAAsC/C,EAC1C,WAAAE,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,wBACd"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class e extends Error{constructor(e){super(e),this.name="SitelineError"}}class t extends e{constructor(e){super(e),this.name="SitelineValidationError"}}class s extends e{constructor(e){super(e),this.name="SitelineTransportError"}}const i=/^siteline_secret_[a-f0-9]{32}$/;class n{constructor(e){if(!e.websiteKey?.match(i))throw new t("Invalid websiteKey format. Expected: siteline_secret_<32 hex chars>");if(this.key=e.websiteKey,this.endpoint=e.endpoint||"https://siteline.ai/v1/intake/pageview",this.debug=e.debug||!1,this.sdk=e.sdk||"@siteline/core",this.sdkVersion=e.sdkVersion||"1.0.0",this.integrationType=e.integrationType||"custom",!this.endpoint.startsWith("https://"))throw new t("Endpoint must use HTTPS");this.debug&&console.log("[Siteline] Siteline initialized")}track(e){const t=this.sanitize(e);this.send(t).catch(e=>{this.debug&&console.error("[Siteline] Track failed:",e.message)})}sanitize(e){return{websiteKey:this.key,url:(e.url+"").slice(0,2048),method:(e.method+"").toUpperCase().slice(0,10),status:Math.max(0,Math.min(999,Number(e.status)||0)),duration:Math.max(0,Math.min(3e5,Number(e.duration)||0)),userAgent:e.userAgent?(e.userAgent+"").slice(0,512):null,ref:e.ref?(e.ref+"").slice(0,2048):null,ip:e.ip?(e.ip+"").slice(0,45):null,integration_type:this.integrationType.slice(0,50),sdk:this.sdk.slice(0,50),sdk_version:this.sdkVersion.slice(0,20)}}async send(e){const t=new AbortController,s=setTimeout(()=>t.abort(),5e3);try{const s=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json","User-Agent":`${this.sdk}/${this.sdkVersion}`},body:JSON.stringify(e),signal:t.signal});this.debug&&(s.ok?console.log("[Siteline] Tracked:",e.url):console.error("[Siteline] HTTP error:",s.status))}catch(e){this.debug&&console.error("[Siteline] Network error:",e.message)}finally{clearTimeout(s)}}}export{n as Siteline,e as SitelineError,s as SitelineTransportError,t as SitelineValidationError};
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/errors.ts","../src/constants.ts","../src/siteline.ts"],"sourcesContent":[null,null,null],"names":["SitelineError","Error","constructor","message","super","this","name","SitelineValidationError","SitelineTransportError","WEBSITEKEY_PATTERN","Siteline","config","websiteKey","match","key","endpoint","debug","sdk","sdkVersion","integrationType","startsWith","console","log","track","data","sanitized","sanitize","send","catch","err","error","url","String","slice","method","toUpperCase","status","Math","max","min","Number","duration","userAgent","ref","ip","integration_type","sdk_version","controller","AbortController","timeout","setTimeout","abort","res","fetch","headers","body","JSON","stringify","signal","ok","clearTimeout"],"mappings":"AAAM,MAAOA,UAAsBC,MACjC,WAAAC,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,eACd,EAGI,MAAOC,UAAgCP,EAC3C,WAAAE,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,yBACd,EAGI,MAAOE,UAA+BR,EAC1C,WAAAE,CAAYC,GACVC,MAAMD,GACNE,KAAKC,KAAO,wBACd,EClBK,MAKMG,EAAqB,uCCOrBC,EAQX,WAAAR,CAAYS,GACV,IAAKA,EAAOC,YAAYC,MAAMJ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We,MAAM,EDlDf,ICoDxB,CAEQ,UAAMN,CAAKH,GACjB,MAAMuB,EAAa,IAAIC,gBACjBC,EAAUC,WAAW,IAAMH,EAAWI,QDjDtB,KCmDtB,IACE,MAAMC,QAAYC,MAAMhD,KAAKU,SAAU,CACrCmB,OAAQ,OACRoB,QAAS,CACP,eAAgB,mBAChB,aAAc,GAAGjD,KAAKY,OAAOZ,KAAKa,cAEpCqC,KAAMC,KAAKC,UAAUjC,GACrBkC,OAAQX,EAAWW,SAGjBrD,KAAKW,QACHoC,EAAIO,GACNtC,QAAQC,IAAI,sBAAuBE,EAAKO,KAExCV,QAAQS,MAAM,yBAA0BsB,EAAIhB,QAGlD,CAAE,MAAOP,GACHxB,KAAKW,OAEPK,QAAQS,MAAM,4BADAD,EACmC1B,QAErD,SACEyD,aAAaX,EACf,CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PageviewData, SitelineConfig } from './types';
|
|
2
|
+
export declare class Siteline {
|
|
3
|
+
private readonly key;
|
|
4
|
+
private readonly endpoint;
|
|
5
|
+
private readonly debug;
|
|
6
|
+
private readonly sdk;
|
|
7
|
+
private readonly sdkVersion;
|
|
8
|
+
private readonly integrationType;
|
|
9
|
+
constructor(config: SitelineConfig);
|
|
10
|
+
track(data: PageviewData): void;
|
|
11
|
+
private sanitize;
|
|
12
|
+
private send;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=siteline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"siteline.d.ts","sourceRoot":"","sources":["../src/siteline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAY5D,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,MAAM,EAAE,cAAc;IAuBlC,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAU/B,OAAO,CAAC,QAAQ;YAgBF,IAAI;CA+BnB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type PageviewData = {
|
|
2
|
+
url: string;
|
|
3
|
+
method: string;
|
|
4
|
+
userAgent: string | null;
|
|
5
|
+
ref: string | null;
|
|
6
|
+
ip: string | null;
|
|
7
|
+
status: number;
|
|
8
|
+
duration: number;
|
|
9
|
+
};
|
|
10
|
+
export type SitelineConfig = {
|
|
11
|
+
websiteKey: string;
|
|
12
|
+
endpoint?: string;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
sdk?: string;
|
|
15
|
+
sdkVersion?: string;
|
|
16
|
+
integrationType?: string;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IAEzB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAElB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@siteline/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Core tracking SDK for Siteline - Agent Analytics platform for tracking AI agents, bots, and crawlers",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rollup -c && tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist",
|
|
22
|
+
"dev": "rollup -c -w",
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"test:watch": "jest --watch",
|
|
27
|
+
"test:coverage": "jest --coverage",
|
|
28
|
+
"prepublishOnly": "npm run build",
|
|
29
|
+
"publish": "npm publish --access public"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"siteline",
|
|
33
|
+
"agent-analytics",
|
|
34
|
+
"ai-agents",
|
|
35
|
+
"bot-detection",
|
|
36
|
+
"crawler-tracking",
|
|
37
|
+
"openai",
|
|
38
|
+
"perplexity",
|
|
39
|
+
"anthropic",
|
|
40
|
+
"google-bot",
|
|
41
|
+
"llm",
|
|
42
|
+
"ai-visibility",
|
|
43
|
+
"sdk",
|
|
44
|
+
"typescript",
|
|
45
|
+
"edge",
|
|
46
|
+
"cloudflare",
|
|
47
|
+
"vercel",
|
|
48
|
+
"analytics",
|
|
49
|
+
"monitoring"
|
|
50
|
+
],
|
|
51
|
+
"author": "Siteline <support@siteline.ai> (https://siteline.ai)",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "https://github.com/siteline-ai/siteline-sdk-js",
|
|
56
|
+
"directory": "packages/core"
|
|
57
|
+
},
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/siteline-ai/siteline-sdk-js/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/siteline-ai/siteline-sdk-js/tree/main/packages/core#readme",
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18.0.0"
|
|
64
|
+
},
|
|
65
|
+
"publishConfig": {
|
|
66
|
+
"access": "public"
|
|
67
|
+
}
|
|
68
|
+
}
|