helm-analytics 1.1.0 → 5.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/README.md +23 -0
- package/index.js +30 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -36,3 +36,26 @@ app.post('/purchase', (req, res) => {
|
|
|
36
36
|
res.json({ success: true });
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
|
+
|
|
40
|
+
## Custom Event Tracking (NEW v5)
|
|
41
|
+
|
|
42
|
+
Track specific business events with custom properties:
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
app.post('/signup', (req, res) => {
|
|
46
|
+
// ... logic ...
|
|
47
|
+
helm.trackEvent(req, 'signup_success', { plan: 'growth', method: 'google' });
|
|
48
|
+
res.json({ status: 'ok' });
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Session Stitching
|
|
53
|
+
|
|
54
|
+
To link server-side events back to the browser session, ensure you pass the `sessionId` (retrieved from `sessionStorage.getItem('helm_session_id')`) in the `X-Helm-Session-Id` header of your frontend API calls.
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- **Non-blocking**: Uses non-blocking fetch calls for event ingestion.
|
|
59
|
+
- **Shield Mode**: Active defense against bots and malicious traffic.
|
|
60
|
+
- **Custom Events**: Track business milestones beyond pageviews.
|
|
61
|
+
- **Session Stitching**: Maintain user journey continuity via headers.
|
package/index.js
CHANGED
|
@@ -48,6 +48,7 @@ class HelmAnalytics {
|
|
|
48
48
|
try {
|
|
49
49
|
const payload = {
|
|
50
50
|
siteId: this.siteId,
|
|
51
|
+
sessionId: req.headers['x-helm-session-id'] || req.sessionId || '', // Support session stitching
|
|
51
52
|
url: req.originalUrl || req.url,
|
|
52
53
|
userAgent: req.headers['user-agent'] || '',
|
|
53
54
|
referrer: req.headers['referer'] || req.headers['referrer'] || '',
|
|
@@ -62,12 +63,12 @@ class HelmAnalytics {
|
|
|
62
63
|
if (shield) {
|
|
63
64
|
const { allowed, reason } = await this.checkShield(payload);
|
|
64
65
|
if (!allowed) {
|
|
65
|
-
console.warn(`Helm Shield Blocked: ${payload.clientIp} Reason: ${reason}`);
|
|
66
|
+
console.warn(`[Helm Shield] Blocked IP: ${payload.clientIp} Reason: ${reason}`);
|
|
66
67
|
return false;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
// Fire and forget
|
|
71
|
+
// Fire and forget
|
|
71
72
|
fetch(`${this.apiUrl}/track`, {
|
|
72
73
|
method: 'POST',
|
|
73
74
|
body: JSON.stringify(payload),
|
|
@@ -81,6 +82,33 @@ class HelmAnalytics {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
// Custom event tracking
|
|
86
|
+
async trackEvent(req, eventName, properties = {}) {
|
|
87
|
+
if (!this.siteId) return true;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const payload = {
|
|
91
|
+
siteId: this.siteId,
|
|
92
|
+
sessionId: req.headers['x-helm-session-id'] || req.sessionId || '',
|
|
93
|
+
eventName: eventName,
|
|
94
|
+
properties: properties,
|
|
95
|
+
url: req.originalUrl || req.url,
|
|
96
|
+
referrer: req.headers['referer'] || req.headers['referrer'] || '',
|
|
97
|
+
isServerSide: true
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
fetch(`${this.apiUrl}/track/event`, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: JSON.stringify(payload),
|
|
103
|
+
headers: { 'Content-Type': 'application/json' }
|
|
104
|
+
}).catch(err => {});
|
|
105
|
+
|
|
106
|
+
return true;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
84
112
|
// Express Middleware
|
|
85
113
|
middleware(options = {}) {
|
|
86
114
|
const shield = options.shield || false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "helm-analytics",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Official Node.js
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "Official Node.js SDK for Helm Analytics",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -22,6 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/Helm-Analytics/sentinel-mvp/tree/main/sdk/node"
|
|
26
26
|
}
|
|
27
27
|
}
|