fleek-track-analytics 1.17.27 → 1.17.29
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/NEXTJS_INTEGRATION_GUIDE.md +121 -0
- package/create-browser-bundle.js +55 -0
- package/lib/track-analytics-types.d.ts +4 -4
- package/lib/web/analytics-tool/rudderstack-default-config.d.ts +4 -0
- package/lib/web/analytics-tool/rudderstack-default-config.js +8 -0
- package/lib/web/analytics-tool/rudderstack-default-config.js.map +1 -0
- package/lib/web/analytics-tool/rudderstack-event-routing.js +10 -1
- package/lib/web/analytics-tool/rudderstack-event-routing.js.map +1 -1
- package/lib/web/analytics-tool/web-rudderstack.js +2 -1
- package/lib/web/analytics-tool/web-rudderstack.js.map +1 -1
- package/lib/web/track-analytics/track-analytics.js +113 -71
- package/lib/web/track-analytics/track-analytics.js.map +1 -1
- package/package.json +1 -1
- package/test-rudderstack-server.js +72 -0
- package/test-rudderstack.html +301 -0
- package/test-rudderstack.js +123 -0
- package/test-simple.html +28 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Next.js Integration Guide for RudderStack
|
|
2
|
+
|
|
3
|
+
## Changes Made to Library
|
|
4
|
+
|
|
5
|
+
1. **Event Routing**: Added `product_detail_page_viewed`, `identify`, and `page` to RudderStack routing config
|
|
6
|
+
2. **Default Values**: Hardcoded default RudderStack configuration in the library:
|
|
7
|
+
- Data Plane URL: `https://rudderstack.joinfleek.com`
|
|
8
|
+
- Write Key: `37DB5IcrJ9GQNtcww0uenrGfy0p`
|
|
9
|
+
3. **Optional Configuration**: `writeKey` and `dataPlaneUrl` are now optional - library uses defaults if not provided
|
|
10
|
+
|
|
11
|
+
## Next.js App Initialization
|
|
12
|
+
|
|
13
|
+
Update your initialization file to enable RudderStack:
|
|
14
|
+
|
|
15
|
+
### Before (Current):
|
|
16
|
+
```typescript
|
|
17
|
+
import { TrackAnalytics } from 'fleek-track-analytics/lib/web';
|
|
18
|
+
import * as Sentry from '@sentry/nextjs';
|
|
19
|
+
|
|
20
|
+
const analyticsException = (e: unknown) => {
|
|
21
|
+
if (process.env.NODE_ENV === 'development') {
|
|
22
|
+
console.error(JSON.stringify(e));
|
|
23
|
+
} else {
|
|
24
|
+
Sentry.captureException(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const analyticsWrapper = new TrackAnalytics({
|
|
29
|
+
platform: 'WEB',
|
|
30
|
+
App: 'CONSUMER_WEB',
|
|
31
|
+
segment: true,
|
|
32
|
+
segmentKey: process.env.NEXT_PUBLIC_SEGMENT_KEY || '',
|
|
33
|
+
devMode: process.env.NODE_ENV === 'development',
|
|
34
|
+
errorHandler: analyticsException,
|
|
35
|
+
// debug: true,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
analyticsWrapper.initAnalytics();
|
|
39
|
+
|
|
40
|
+
export { analyticsWrapper };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### After (With RudderStack Enabled):
|
|
44
|
+
```typescript
|
|
45
|
+
import { TrackAnalytics } from 'fleek-track-analytics/lib/web';
|
|
46
|
+
import * as Sentry from '@sentry/nextjs';
|
|
47
|
+
|
|
48
|
+
const analyticsException = (e: unknown) => {
|
|
49
|
+
if (process.env.NODE_ENV === 'development') {
|
|
50
|
+
console.error(JSON.stringify(e));
|
|
51
|
+
} else {
|
|
52
|
+
Sentry.captureException(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const analyticsWrapper = new TrackAnalytics({
|
|
57
|
+
platform: 'WEB',
|
|
58
|
+
App: 'CONSUMER_WEB',
|
|
59
|
+
segment: true,
|
|
60
|
+
segmentKey: process.env.NEXT_PUBLIC_SEGMENT_KEY || '',
|
|
61
|
+
devMode: process.env.NODE_ENV === 'development',
|
|
62
|
+
errorHandler: analyticsException,
|
|
63
|
+
// debug: true,
|
|
64
|
+
// Enable RudderStack with default values (hardcoded in library)
|
|
65
|
+
rudderstack: {
|
|
66
|
+
enabled: true,
|
|
67
|
+
// writeKey and dataPlaneUrl are optional - defaults are used if not provided
|
|
68
|
+
// writeKey: '37DB5IcrJ9GQNtcww0uenrGfy0p', // Optional - uses default
|
|
69
|
+
// dataPlaneUrl: 'https://rudderstack.joinfleek.com', // Optional - uses default
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
analyticsWrapper.initAnalytics();
|
|
74
|
+
|
|
75
|
+
export { analyticsWrapper };
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Events Sent to RudderStack
|
|
79
|
+
|
|
80
|
+
With the current configuration, the following events will be sent to **both** Segment and RudderStack:
|
|
81
|
+
|
|
82
|
+
- `product_detail_page_viewed` - Track events
|
|
83
|
+
- `identify` - Identify events
|
|
84
|
+
- `page` - Page view events
|
|
85
|
+
|
|
86
|
+
All other events will continue to be sent to **Segment only**.
|
|
87
|
+
|
|
88
|
+
## How It Works
|
|
89
|
+
|
|
90
|
+
1. **Dual-Send**: Events are sent to both Segment and RudderStack (when configured)
|
|
91
|
+
2. **Independent**: If Segment fails, RudderStack continues working and vice versa
|
|
92
|
+
3. **Default Values**: The library uses hardcoded defaults for RudderStack URL and write key
|
|
93
|
+
4. **No Breaking Changes**: Existing Segment functionality remains unchanged
|
|
94
|
+
|
|
95
|
+
## Testing
|
|
96
|
+
|
|
97
|
+
After updating the initialization:
|
|
98
|
+
|
|
99
|
+
1. Deploy to your test environment
|
|
100
|
+
2. Trigger a `product_detail_page_viewed` event
|
|
101
|
+
3. Check both Segment and RudderStack dashboards to verify events are received
|
|
102
|
+
4. Test `identify` and `page` events as well
|
|
103
|
+
|
|
104
|
+
## Overriding Defaults (Optional)
|
|
105
|
+
|
|
106
|
+
If you need to override the default values, you can provide them explicitly:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
rudderstack: {
|
|
110
|
+
enabled: true,
|
|
111
|
+
writeKey: 'your-custom-write-key', // Override default
|
|
112
|
+
dataPlaneUrl: 'https://your-custom-url.com', // Override default
|
|
113
|
+
},
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Notes
|
|
117
|
+
|
|
118
|
+
- Default values are hardcoded in `src/web/analytics-tool/rudderstack-default-config.ts`
|
|
119
|
+
- Event routing is configured in `src/web/analytics-tool/rudderstack-event-routing.ts`
|
|
120
|
+
- Both can be modified in the library repository without requiring app changes
|
|
121
|
+
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple script to create a browser-compatible bundle
|
|
3
|
+
* This uses Node.js to load and re-export the CommonJS module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
// Load the built library
|
|
10
|
+
const libPath = path.join(__dirname, 'lib', 'web', 'index.js');
|
|
11
|
+
const lib = require(libPath);
|
|
12
|
+
|
|
13
|
+
// Create a simple browser bundle
|
|
14
|
+
const bundle = `
|
|
15
|
+
// Browser-compatible bundle for fleek-track-analytics
|
|
16
|
+
(function() {
|
|
17
|
+
'use strict';
|
|
18
|
+
|
|
19
|
+
// Export TrackAnalytics to window object
|
|
20
|
+
if (typeof window !== 'undefined') {
|
|
21
|
+
window.FleekTrackAnalytics = ${JSON.stringify(
|
|
22
|
+
{
|
|
23
|
+
TrackAnalytics: lib.TrackAnalytics.toString(),
|
|
24
|
+
},
|
|
25
|
+
null,
|
|
26
|
+
2,
|
|
27
|
+
)};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// For ES modules
|
|
31
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
32
|
+
module.exports = lib;
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
// Actually, let's create a proper ES module wrapper
|
|
38
|
+
const esModuleBundle = `// ES Module wrapper for browser
|
|
39
|
+
import * as lib from './lib/web/index.js';
|
|
40
|
+
export const TrackAnalytics = lib.TrackAnalytics;
|
|
41
|
+
export const WebTraceManager = lib.WebTraceManager;
|
|
42
|
+
export const createWebTraceManager = lib.createWebTraceManager;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
// Better approach: Create a simple loader script
|
|
46
|
+
const loaderScript = `
|
|
47
|
+
// Simple loader that works with the CommonJS build
|
|
48
|
+
// This requires the server to handle the module correctly
|
|
49
|
+
console.log('Note: The library needs to be served with proper MIME types and module support');
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
console.log('Creating browser bundle...');
|
|
53
|
+
|
|
54
|
+
// For now, let's create a simple HTML that uses a script tag approach
|
|
55
|
+
// We'll need to use a bundler or serve it differently
|
|
@@ -16,8 +16,8 @@ export interface IAnalyticsInit {
|
|
|
16
16
|
};
|
|
17
17
|
rudderstack?: {
|
|
18
18
|
enabled: boolean;
|
|
19
|
-
writeKey
|
|
20
|
-
dataPlaneUrl
|
|
19
|
+
writeKey?: string;
|
|
20
|
+
dataPlaneUrl?: string;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
export interface ITrackAnalyticsParams {
|
|
@@ -36,8 +36,8 @@ export interface ITrackAnalyticsParams {
|
|
|
36
36
|
};
|
|
37
37
|
rudderstack?: {
|
|
38
38
|
enabled: boolean;
|
|
39
|
-
writeKey
|
|
40
|
-
dataPlaneUrl
|
|
39
|
+
writeKey?: string;
|
|
40
|
+
dataPlaneUrl?: string;
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
export type AnyDataType = string | boolean | number | null | undefined | AnyDataArray | AnyDataObject;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RUDDERSTACK_DEFAULT_CONFIG = void 0;
|
|
4
|
+
exports.RUDDERSTACK_DEFAULT_CONFIG = {
|
|
5
|
+
dataPlaneUrl: 'https://rudderstack.joinfleek.com',
|
|
6
|
+
writeKey: '37DB5IcrJ9GQNtcww0uenrGfy0p',
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=rudderstack-default-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rudderstack-default-config.js","sourceRoot":"","sources":["../../../src/web/analytics-tool/rudderstack-default-config.ts"],"names":[],"mappings":";;;AAKa,QAAA,0BAA0B,GAAG;IAExC,YAAY,EAAE,mCAAmC;IAEjD,QAAQ,EAAE,6BAA6B;CACxC,CAAC"}
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rudderstackEventRouting = void 0;
|
|
4
4
|
exports.rudderstackEventRouting = {
|
|
5
|
-
sendToRudderstack: [
|
|
5
|
+
sendToRudderstack: [
|
|
6
|
+
'product_detail_page_viewed',
|
|
7
|
+
'identify',
|
|
8
|
+
'page',
|
|
9
|
+
'homescreen',
|
|
10
|
+
'homescreen_viewed',
|
|
11
|
+
'product_tile_clicked',
|
|
12
|
+
'session_started',
|
|
13
|
+
'collection_viewed',
|
|
14
|
+
],
|
|
6
15
|
};
|
|
7
16
|
//# sourceMappingURL=rudderstack-event-routing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rudderstack-event-routing.js","sourceRoot":"","sources":["../../../src/web/analytics-tool/rudderstack-event-routing.ts"],"names":[],"mappings":";;;AAwBa,QAAA,uBAAuB,GAA6B;IAC/D,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"rudderstack-event-routing.js","sourceRoot":"","sources":["../../../src/web/analytics-tool/rudderstack-event-routing.ts"],"names":[],"mappings":";;;AAwBa,QAAA,uBAAuB,GAA6B;IAC/D,iBAAiB,EAAE;QACjB,4BAA4B;QAC5B,UAAU;QACV,MAAM;QACN,YAAY;QACZ,mBAAmB;QACnB,sBAAsB;QACtB,iBAAiB;QACjB,mBAAmB;KACpB;CAGF,CAAC"}
|
|
@@ -5,7 +5,8 @@ const analytics_js_1 = require("@rudderstack/analytics-js");
|
|
|
5
5
|
const package_json_1 = require("../../../package.json");
|
|
6
6
|
const webRudderstack = ({ writeKey, dataPlaneUrl, app, debug, dimenstionsManager }) => {
|
|
7
7
|
const rudderanalytics = new analytics_js_1.RudderAnalytics();
|
|
8
|
-
|
|
8
|
+
const normalizedDataPlaneUrl = dataPlaneUrl.endsWith('/') ? dataPlaneUrl.slice(0, -1) : dataPlaneUrl;
|
|
9
|
+
rudderanalytics.load(writeKey, normalizedDataPlaneUrl, {
|
|
9
10
|
anonymousIdOptions: {
|
|
10
11
|
autoCapture: {
|
|
11
12
|
enabled: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-rudderstack.js","sourceRoot":"","sources":["../../../src/web/analytics-tool/web-rudderstack.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAE5D,wDAAgD;AAWzC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,EAAE,kBAAkB,EAA6B,EAAE,EAAE;IAEtH,MAAM,eAAe,GAAG,IAAI,8BAAe,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"web-rudderstack.js","sourceRoot":"","sources":["../../../src/web/analytics-tool/web-rudderstack.ts"],"names":[],"mappings":";;;AAAA,4DAA4D;AAE5D,wDAAgD;AAWzC,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,EAAE,KAAK,EAAE,kBAAkB,EAA6B,EAAE,EAAE;IAEtH,MAAM,eAAe,GAAG,IAAI,8BAAe,EAAE,CAAC;IAI9C,MAAM,sBAAsB,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IAGrG,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,sBAAsB,EAAE;QAErD,kBAAkB,EAAE;YAClB,WAAW,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4
4
|
const web_segment_1 = require("../analytics-tool/web-segment");
|
|
5
5
|
const web_rudderstack_1 = require("../analytics-tool/web-rudderstack");
|
|
6
6
|
const rudderstack_event_routing_1 = require("../analytics-tool/rudderstack-event-routing");
|
|
7
|
+
const rudderstack_default_config_1 = require("../analytics-tool/rudderstack-default-config");
|
|
7
8
|
const dimension_manager_1 = require("../utils/DImentsionManager/dimension-manager");
|
|
8
9
|
const isbot_1 = require("isbot");
|
|
9
10
|
const check_env_1 = require("../utils/check-env");
|
|
@@ -16,96 +17,142 @@ class TrackAnalytics {
|
|
|
16
17
|
this.traceManager = null;
|
|
17
18
|
this.initAnalytics = async () => {
|
|
18
19
|
var _a, _b;
|
|
20
|
+
if (!(0, check_env_1.isBrowser)()) {
|
|
21
|
+
this.initParams.errorHandler(new Error('TrackAnalytics can only be initialized in a browser environment'));
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.isCrawlerOrBot = (0, isbot_1.isbot)(navigator.userAgent);
|
|
25
|
+
if (this.isCrawlerOrBot) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
19
28
|
try {
|
|
20
|
-
if (!(0, check_env_1.isBrowser)()) {
|
|
21
|
-
throw new Error('TrackAnalytics can only be initialized in a browser environment');
|
|
22
|
-
}
|
|
23
|
-
this.isCrawlerOrBot = (0, isbot_1.isbot)(navigator.userAgent);
|
|
24
|
-
if (this.isCrawlerOrBot) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
29
|
this.dimensionManager.init();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.initParams.errorHandler(new Error(`Dimension manager init failed: ${error instanceof Error ? error.message : String(error)}. Continuing with SDK initialization.`));
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
28
35
|
this.analyticsWrapper = (0, web_segment_1.webSegment)({
|
|
29
36
|
segmentKey: this.initParams.segmentKey,
|
|
30
37
|
app: this.initParams.App,
|
|
31
38
|
dimenstionsManager: this.dimensionManager,
|
|
32
39
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.initParams.errorHandler(new Error(`Segment initialization failed: ${error instanceof Error ? error.message : String(error)}. Continuing with RudderStack if enabled.`));
|
|
43
|
+
this.analyticsWrapper = null;
|
|
44
|
+
}
|
|
45
|
+
if ((_a = this.initParams.rudderstack) === null || _a === void 0 ? void 0 : _a.enabled) {
|
|
46
|
+
try {
|
|
47
|
+
const writeKey = this.initParams.rudderstack.writeKey || rudderstack_default_config_1.RUDDERSTACK_DEFAULT_CONFIG.writeKey;
|
|
48
|
+
const dataPlaneUrl = this.initParams.rudderstack.dataPlaneUrl || rudderstack_default_config_1.RUDDERSTACK_DEFAULT_CONFIG.dataPlaneUrl;
|
|
49
|
+
this.rudderstackWrapper = (0, web_rudderstack_1.webRudderstack)({
|
|
50
|
+
writeKey,
|
|
51
|
+
dataPlaneUrl,
|
|
52
|
+
app: this.initParams.App,
|
|
53
|
+
debug: this.initParams.debug,
|
|
54
|
+
dimenstionsManager: this.dimensionManager,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.initParams.errorHandler(new Error(`RudderStack initialization failed: ${error instanceof Error ? error.message : String(error)}. Continuing with Segment if available.`));
|
|
59
|
+
this.rudderstackWrapper = null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if ((_b = this.initParams.traceManager) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
63
|
+
try {
|
|
48
64
|
this.traceManager = (0, index_1.createWebTraceManager)(this.initParams.traceManager);
|
|
49
65
|
await this.traceManager.initialize();
|
|
50
66
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
67
|
+
catch (error) {
|
|
68
|
+
this.initParams.errorHandler(new Error(`Trace manager initialization failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
69
|
+
}
|
|
54
70
|
}
|
|
55
71
|
};
|
|
56
72
|
this.track = async (...args) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
if (!this.checkInitDone()) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const [eventName, properties] = args;
|
|
77
|
+
if (this.isCrawlerOrBot) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const enrichedEvent = this.enrichEvent(eventName, properties);
|
|
81
|
+
if (this.analyticsWrapper) {
|
|
82
|
+
try {
|
|
83
|
+
await this.analyticsWrapper.track(eventName, enrichedEvent);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.initParams.errorHandler(new Error(`Segment track failed for event ${eventName}: ${error instanceof Error ? error.message : String(error)}`));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (this.rudderstackWrapper && this.shouldSendToRudderstack(eventName)) {
|
|
90
|
+
try {
|
|
91
|
+
await this.rudderstackWrapper.track(eventName, enrichedEvent);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.initParams.errorHandler(new Error(`RudderStack track failed for event ${eventName}: ${error instanceof Error ? error.message : String(error)}`));
|
|
72
95
|
}
|
|
73
96
|
}
|
|
74
97
|
};
|
|
75
98
|
this.identify = async (id, traits) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
if (!this.checkInitDone()) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const enrichedTraits = this.enrichEvent('identify', traits);
|
|
103
|
+
if (this.analyticsWrapper) {
|
|
104
|
+
try {
|
|
105
|
+
await this.analyticsWrapper.identify(id, enrichedTraits);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
this.initParams.errorHandler(new Error(`Segment identify failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (this.rudderstackWrapper && this.shouldSendToRudderstack('identify')) {
|
|
112
|
+
try {
|
|
113
|
+
await this.rudderstackWrapper.identify(id, enrichedTraits);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.initParams.errorHandler(new Error(`RudderStack identify failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
87
117
|
}
|
|
88
118
|
}
|
|
89
119
|
};
|
|
90
120
|
this.page = async (params) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
if (!this.checkInitDone()) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const enrichedParams = this.enrichEvent('page', params);
|
|
125
|
+
if (this.analyticsWrapper) {
|
|
126
|
+
try {
|
|
127
|
+
await this.analyticsWrapper.page(enrichedParams);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
this.initParams.errorHandler(new Error(`Segment page failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (this.rudderstackWrapper && this.shouldSendToRudderstack('page')) {
|
|
134
|
+
try {
|
|
135
|
+
await this.rudderstackWrapper.page(enrichedParams);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
this.initParams.errorHandler(new Error(`RudderStack page failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
102
139
|
}
|
|
103
140
|
}
|
|
104
141
|
};
|
|
105
142
|
this.getAnonymousId = async () => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
143
|
+
if (this.analyticsWrapper) {
|
|
144
|
+
try {
|
|
145
|
+
return await this.analyticsWrapper.getAnonymousId();
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (this.rudderstackWrapper) {
|
|
151
|
+
try {
|
|
152
|
+
return await this.rudderstackWrapper.getAnonymousId();
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
}
|
|
109
156
|
}
|
|
110
157
|
return Promise.resolve(undefined);
|
|
111
158
|
};
|
|
@@ -133,12 +180,7 @@ class TrackAnalytics {
|
|
|
133
180
|
this.dimensionManager = new dimension_manager_1.DimentionsManger();
|
|
134
181
|
}
|
|
135
182
|
checkInitDone() {
|
|
136
|
-
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
183
|
+
return this.analyticsWrapper !== null || this.rudderstackWrapper !== null;
|
|
142
184
|
}
|
|
143
185
|
enrichEvent(eventName, eventParams = {}) {
|
|
144
186
|
if (!this.traceManager) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"track-analytics.js","sourceRoot":"","sources":["../../../src/web/track-analytics/track-analytics.ts"],"names":[],"mappings":";;;AAEA,+DAA2D;AAC3D,uEAAmE;AACnE,2FAAsF;AACtF,oFAAgF;AAChF,iCAA8B;AAC9B,kDAA+C;AAC/C,oCAAiD;AAEjD,MAAM,cAAc;IAQlB,YAAY,MAAsB;QAN1B,qBAAgB,GAAgC,IAAI,CAAC;QACrD,uBAAkB,GAAgC,IAAI,CAAC;QAEvD,mBAAc,GAAY,KAAK,CAAC;QAChC,iBAAY,GAAoD,IAAI,CAAC;QAkB7E,kBAAa,GAAG,KAAK,IAAI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AC,SAAS,CAAC,EAAE,CAAC;YAC7E,OAAO,IAAI,CAAC;QACd,CAAC;QAGD,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5D,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC3C,IAAI,CAAC;oBACH,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC7C,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAEf,IAAI,CAAC,UAAU,CAAC,YAAY,CAC1B,IAAI,KAAK,CACP,uDAAuD,OAAO,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACnI,CACF,CAAC;oBACF,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CA0IF;AAEQ,wCAAc"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple HTTP server to test RudderStack integration
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* 1. Build the library: yarn build
|
|
6
|
+
* 2. Run this server: node test-rudderstack-server.js
|
|
7
|
+
* 3. Open http://localhost:3000 in your browser
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const http = require('http');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const PORT = 3000;
|
|
15
|
+
|
|
16
|
+
const server = http.createServer((req, res) => {
|
|
17
|
+
let filePath = '.' + req.url;
|
|
18
|
+
|
|
19
|
+
if (filePath === './') {
|
|
20
|
+
filePath = './test-rudderstack.html';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const extname = String(path.extname(filePath)).toLowerCase();
|
|
24
|
+
const mimeTypes = {
|
|
25
|
+
'.html': 'text/html',
|
|
26
|
+
'.js': 'text/javascript',
|
|
27
|
+
'.mjs': 'text/javascript',
|
|
28
|
+
'.css': 'text/css',
|
|
29
|
+
'.json': 'application/json',
|
|
30
|
+
'.png': 'image/png',
|
|
31
|
+
'.jpg': 'image/jpg',
|
|
32
|
+
'.gif': 'image/gif',
|
|
33
|
+
'.svg': 'image/svg+xml',
|
|
34
|
+
'.wav': 'audio/wav',
|
|
35
|
+
'.mp4': 'video/mp4',
|
|
36
|
+
'.woff': 'application/font-woff',
|
|
37
|
+
'.ttf': 'application/font-ttf',
|
|
38
|
+
'.eot': 'application/vnd.ms-fontobject',
|
|
39
|
+
'.otf': 'application/font-otf',
|
|
40
|
+
'.wasm': 'application/wasm',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const contentType = mimeTypes[extname] || 'application/octet-stream';
|
|
44
|
+
|
|
45
|
+
fs.readFile(filePath, (error, content) => {
|
|
46
|
+
if (error) {
|
|
47
|
+
if (error.code === 'ENOENT') {
|
|
48
|
+
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
49
|
+
res.end('<h1>404 - File Not Found</h1>', 'utf-8');
|
|
50
|
+
} else {
|
|
51
|
+
res.writeHead(500);
|
|
52
|
+
res.end(`Server Error: ${error.code}`, 'utf-8');
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
res.writeHead(200, { 'Content-Type': contentType });
|
|
56
|
+
res.end(content, 'utf-8');
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
server.listen(PORT, () => {
|
|
62
|
+
console.log(`🚀 Test server running at http://localhost:${PORT}`);
|
|
63
|
+
console.log(`📝 Open http://localhost:${PORT} in your browser to test`);
|
|
64
|
+
console.log(`\n⚠️ Make sure you have:`);
|
|
65
|
+
console.log(` 1. Built the library: yarn build`);
|
|
66
|
+
console.log(` 2. Set SEGMENT_KEY environment variable (or enter it in the form)`);
|
|
67
|
+
console.log(`\n🔍 The test page will allow you to:`);
|
|
68
|
+
console.log(` - Initialize analytics with RudderStack`);
|
|
69
|
+
console.log(` - Send identify events`);
|
|
70
|
+
console.log(` - Send test_event track events`);
|
|
71
|
+
console.log(`\n📊 Check RudderStack dashboard at: http://35.233.238.142\n`);
|
|
72
|
+
});
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>RudderStack Integration Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
max-width: 800px;
|
|
11
|
+
margin: 50px auto;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
background: #f5f5f5;
|
|
14
|
+
}
|
|
15
|
+
.container {
|
|
16
|
+
background: white;
|
|
17
|
+
padding: 30px;
|
|
18
|
+
border-radius: 8px;
|
|
19
|
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
20
|
+
}
|
|
21
|
+
h1 {
|
|
22
|
+
color: #333;
|
|
23
|
+
}
|
|
24
|
+
.config {
|
|
25
|
+
background: #f9f9f9;
|
|
26
|
+
padding: 15px;
|
|
27
|
+
border-radius: 4px;
|
|
28
|
+
margin: 20px 0;
|
|
29
|
+
}
|
|
30
|
+
.config label {
|
|
31
|
+
display: block;
|
|
32
|
+
margin: 10px 0 5px 0;
|
|
33
|
+
font-weight: bold;
|
|
34
|
+
}
|
|
35
|
+
.config input {
|
|
36
|
+
width: 100%;
|
|
37
|
+
padding: 8px;
|
|
38
|
+
border: 1px solid #ddd;
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
}
|
|
42
|
+
button {
|
|
43
|
+
background: #007bff;
|
|
44
|
+
color: white;
|
|
45
|
+
border: none;
|
|
46
|
+
padding: 12px 24px;
|
|
47
|
+
border-radius: 4px;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
font-size: 16px;
|
|
50
|
+
margin: 10px 5px;
|
|
51
|
+
}
|
|
52
|
+
button:hover {
|
|
53
|
+
background: #0056b3;
|
|
54
|
+
}
|
|
55
|
+
button:disabled {
|
|
56
|
+
background: #ccc;
|
|
57
|
+
cursor: not-allowed;
|
|
58
|
+
}
|
|
59
|
+
.log {
|
|
60
|
+
background: #1e1e1e;
|
|
61
|
+
color: #d4d4d4;
|
|
62
|
+
padding: 15px;
|
|
63
|
+
border-radius: 4px;
|
|
64
|
+
margin-top: 20px;
|
|
65
|
+
font-family: 'Courier New', monospace;
|
|
66
|
+
font-size: 12px;
|
|
67
|
+
max-height: 400px;
|
|
68
|
+
overflow-y: auto;
|
|
69
|
+
}
|
|
70
|
+
.log-entry {
|
|
71
|
+
margin: 5px 0;
|
|
72
|
+
padding: 5px;
|
|
73
|
+
}
|
|
74
|
+
.log-success {
|
|
75
|
+
color: #4ec9b0;
|
|
76
|
+
}
|
|
77
|
+
.log-error {
|
|
78
|
+
color: #f48771;
|
|
79
|
+
}
|
|
80
|
+
.log-info {
|
|
81
|
+
color: #569cd6;
|
|
82
|
+
}
|
|
83
|
+
.status {
|
|
84
|
+
padding: 10px;
|
|
85
|
+
margin: 10px 0;
|
|
86
|
+
border-radius: 4px;
|
|
87
|
+
}
|
|
88
|
+
.status.ready {
|
|
89
|
+
background: #d4edda;
|
|
90
|
+
color: #155724;
|
|
91
|
+
}
|
|
92
|
+
.status.error {
|
|
93
|
+
background: #f8d7da;
|
|
94
|
+
color: #721c24;
|
|
95
|
+
}
|
|
96
|
+
</style>
|
|
97
|
+
</head>
|
|
98
|
+
<body>
|
|
99
|
+
<div class="container">
|
|
100
|
+
<h1>🚀 RudderStack Integration Test</h1>
|
|
101
|
+
|
|
102
|
+
<div class="config">
|
|
103
|
+
<h3>Configuration</h3>
|
|
104
|
+
<label>Segment Write Key:</label>
|
|
105
|
+
<input type="text" id="segmentKey" value="aozA9TyblW1sk5qnZTdjewY2rxEU9ojR" readonly />
|
|
106
|
+
|
|
107
|
+
<label>RudderStack Data Plane URL:</label>
|
|
108
|
+
<input type="text" id="dataPlaneUrl" value="https://rudderstack.joinfleek.com" readonly />
|
|
109
|
+
|
|
110
|
+
<label>RudderStack Write Key:</label>
|
|
111
|
+
<input type="text" id="rudderstackKey" value="37DB5IcrJ9GQNtcww0uenrGfy0p" readonly />
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div id="status" class="status" style="display: none"></div>
|
|
115
|
+
|
|
116
|
+
<div>
|
|
117
|
+
<button id="initBtn" onclick="initializeAnalytics()">Initialize Analytics</button>
|
|
118
|
+
<button id="identifyBtn" onclick="sendIdentify()" disabled>Send Identify Event</button>
|
|
119
|
+
<button id="testEventBtn" onclick="sendTestEvent()" disabled>Send Test Event</button>
|
|
120
|
+
<button onclick="clearLog()">Clear Log</button>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<div class="log" id="log"></div>
|
|
124
|
+
</div>
|
|
125
|
+
|
|
126
|
+
<!-- Load the built library -->
|
|
127
|
+
<script type="module">
|
|
128
|
+
// Import the TrackAnalytics from the built library
|
|
129
|
+
// Note: This requires the library to be built and served properly
|
|
130
|
+
// For testing, you may need to adjust the import path
|
|
131
|
+
|
|
132
|
+
let analytics = null;
|
|
133
|
+
let initialized = false;
|
|
134
|
+
|
|
135
|
+
window.initializeAnalytics = async function () {
|
|
136
|
+
const log = document.getElementById('log');
|
|
137
|
+
const status = document.getElementById('status');
|
|
138
|
+
const segmentKey = document.getElementById('segmentKey').value;
|
|
139
|
+
const dataPlaneUrl = document.getElementById('dataPlaneUrl').value;
|
|
140
|
+
const rudderstackKey = document.getElementById('rudderstackKey').value;
|
|
141
|
+
|
|
142
|
+
// Segment key is now hardcoded, but still check if it exists
|
|
143
|
+
if (!segmentKey) {
|
|
144
|
+
addLog('❌ Error: Segment write key is required', 'error');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
addLog('🚀 Initializing analytics...', 'info');
|
|
150
|
+
|
|
151
|
+
// Load the browser-bundled library
|
|
152
|
+
let TrackAnalytics;
|
|
153
|
+
const basePath = window.location.pathname.replace(/\/[^/]*$/, '');
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
// Try the bundled browser version (.mjs for ES modules)
|
|
157
|
+
const modulePath = `${basePath}/lib/web/browser.mjs`;
|
|
158
|
+
addLog(`Loading from: ${modulePath}`, 'info');
|
|
159
|
+
|
|
160
|
+
const module = await import(modulePath);
|
|
161
|
+
|
|
162
|
+
// The bundle exports default with TrackAnalytics inside
|
|
163
|
+
// Based on Node.js test: module.default.TrackAnalytics exists
|
|
164
|
+
TrackAnalytics = module.default?.TrackAnalytics;
|
|
165
|
+
|
|
166
|
+
if (!TrackAnalytics && module.default) {
|
|
167
|
+
// Try direct access if default is the exports object
|
|
168
|
+
TrackAnalytics = module.default.TrackAnalytics || module.TrackAnalytics;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!TrackAnalytics) {
|
|
172
|
+
addLog(`Module structure: ${JSON.stringify(Object.keys(module))}`, 'error');
|
|
173
|
+
if (module.default) {
|
|
174
|
+
addLog(`Default keys: ${JSON.stringify(Object.keys(module.default))}`, 'error');
|
|
175
|
+
}
|
|
176
|
+
throw new Error('TrackAnalytics not found in module exports');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
addLog('✅ Library loaded from browser bundle', 'success');
|
|
180
|
+
} catch (e1) {
|
|
181
|
+
addLog(`❌ Failed to load library: ${e1.message}`, 'error');
|
|
182
|
+
if (e1.message.includes('Failed to fetch') || e1.message.includes('404')) {
|
|
183
|
+
addLog('💡 The bundle file might not be accessible. Check:', 'info');
|
|
184
|
+
addLog(' 1. The server is running: node test-rudderstack-server.js', 'info');
|
|
185
|
+
addLog(' 2. The bundle exists: ls -la lib/web/browser.mjs', 'info');
|
|
186
|
+
addLog(' 3. The path is correct in the browser', 'info');
|
|
187
|
+
}
|
|
188
|
+
throw new Error(`Could not load TrackAnalytics: ${e1.message}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
analytics = new TrackAnalytics({
|
|
192
|
+
platform: 'WEB',
|
|
193
|
+
App: 'CONSUMER_WEB',
|
|
194
|
+
segment: true,
|
|
195
|
+
segmentKey: segmentKey,
|
|
196
|
+
debug: true,
|
|
197
|
+
errorHandler: (error) => {
|
|
198
|
+
addLog(`❌ Error: ${error.message || error}`, 'error');
|
|
199
|
+
},
|
|
200
|
+
rudderstack: {
|
|
201
|
+
enabled: true,
|
|
202
|
+
writeKey: rudderstackKey,
|
|
203
|
+
dataPlaneUrl: dataPlaneUrl,
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
await analytics.initAnalytics();
|
|
208
|
+
|
|
209
|
+
initialized = true;
|
|
210
|
+
status.className = 'status ready';
|
|
211
|
+
status.textContent = '✅ Analytics initialized successfully';
|
|
212
|
+
status.style.display = 'block';
|
|
213
|
+
|
|
214
|
+
document.getElementById('initBtn').disabled = true;
|
|
215
|
+
document.getElementById('identifyBtn').disabled = false;
|
|
216
|
+
document.getElementById('testEventBtn').disabled = false;
|
|
217
|
+
|
|
218
|
+
addLog('✅ Analytics initialized successfully', 'success');
|
|
219
|
+
addLog('📊 RudderStack is enabled and configured', 'info');
|
|
220
|
+
addLog(` Data Plane: ${dataPlaneUrl}`, 'info');
|
|
221
|
+
} catch (error) {
|
|
222
|
+
addLog(`❌ Initialization failed: ${error.message}`, 'error');
|
|
223
|
+
status.className = 'status error';
|
|
224
|
+
status.textContent = `❌ Initialization failed: ${error.message}`;
|
|
225
|
+
status.style.display = 'block';
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
window.sendIdentify = async function () {
|
|
230
|
+
if (!initialized || !analytics) {
|
|
231
|
+
addLog('❌ Analytics not initialized', 'error');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
addLog('📤 Sending IDENTIFY event...', 'info');
|
|
237
|
+
|
|
238
|
+
await analytics.identify('test-user-123', {
|
|
239
|
+
email: 'test@example.com',
|
|
240
|
+
name: 'Test User',
|
|
241
|
+
testProperty: 'test-value',
|
|
242
|
+
timestamp: new Date().toISOString(),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
addLog('✅ Identify event sent successfully', 'success');
|
|
246
|
+
addLog(' 📊 This event should be sent to BOTH Segment and RudderStack', 'info');
|
|
247
|
+
addLog(' 🔍 Check your RudderStack dashboard to verify', 'info');
|
|
248
|
+
} catch (error) {
|
|
249
|
+
addLog(`❌ Identify event failed: ${error.message}`, 'error');
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
window.sendTestEvent = async function () {
|
|
254
|
+
if (!initialized || !analytics) {
|
|
255
|
+
addLog('❌ Analytics not initialized', 'error');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
addLog('📤 Sending TEST_EVENT (track)...', 'info');
|
|
261
|
+
|
|
262
|
+
// Use track method - note: test_event must be in the routing config
|
|
263
|
+
await analytics.track('test_event', {
|
|
264
|
+
testProperty: 'test-value',
|
|
265
|
+
timestamp: new Date().toISOString(),
|
|
266
|
+
source: 'rudderstack-test-script',
|
|
267
|
+
testData: {
|
|
268
|
+
message: 'This is a test event',
|
|
269
|
+
number: 123,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
addLog('✅ Test event sent successfully', 'success');
|
|
274
|
+
addLog(' 📊 This event should be sent to BOTH Segment and RudderStack', 'info');
|
|
275
|
+
addLog(' 🔍 Check your RudderStack dashboard to verify', 'info');
|
|
276
|
+
} catch (error) {
|
|
277
|
+
addLog(`❌ Test event failed: ${error.message}`, 'error');
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
window.clearLog = function () {
|
|
282
|
+
document.getElementById('log').innerHTML = '';
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
function addLog(message, type = 'info') {
|
|
286
|
+
const log = document.getElementById('log');
|
|
287
|
+
const entry = document.createElement('div');
|
|
288
|
+
entry.className = `log-entry log-${type}`;
|
|
289
|
+
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
|
290
|
+
log.appendChild(entry);
|
|
291
|
+
log.scrollTop = log.scrollHeight;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Initial log message
|
|
295
|
+
addLog('Ready to test RudderStack integration', 'info');
|
|
296
|
+
addLog('✅ Configuration pre-filled (Segment key and RudderStack URL)', 'info');
|
|
297
|
+
addLog('1. Click "Initialize Analytics"', 'info');
|
|
298
|
+
addLog('2. Send test events', 'info');
|
|
299
|
+
</script>
|
|
300
|
+
</body>
|
|
301
|
+
</html>
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test script for RudderStack integration
|
|
3
|
+
*
|
|
4
|
+
* This script tests the dual-send functionality:
|
|
5
|
+
* - Events are sent to both Segment and RudderStack
|
|
6
|
+
* - RudderStack events are controlled by rudderstack-event-routing.ts config
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node test-rudderstack.js
|
|
10
|
+
*
|
|
11
|
+
* Make sure to set SEGMENT_KEY environment variable:
|
|
12
|
+
* export SEGMENT_KEY=your_segment_key
|
|
13
|
+
* node test-rudderstack.js
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// Import the built library (requires build first)
|
|
17
|
+
const { TrackAnalytics } = require('./lib/web');
|
|
18
|
+
|
|
19
|
+
// Configuration
|
|
20
|
+
const RUDDERSTACK_DATA_PLANE_URL = 'http://35.233.238.142';
|
|
21
|
+
const RUDDERSTACK_WRITE_KEY = '37DB5IcrJ9GQNtcww0uenrGfy0p';
|
|
22
|
+
const SEGMENT_KEY = process.env.SEGMENT_KEY || '';
|
|
23
|
+
|
|
24
|
+
if (!SEGMENT_KEY) {
|
|
25
|
+
console.error('❌ Error: SEGMENT_KEY environment variable is required');
|
|
26
|
+
console.log('Please set it with: export SEGMENT_KEY=your_segment_key');
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Error handler
|
|
31
|
+
const errorHandler = (error) => {
|
|
32
|
+
console.error('❌ Analytics Error:', error);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Initialize TrackAnalytics with RudderStack enabled
|
|
36
|
+
const analytics = new TrackAnalytics({
|
|
37
|
+
platform: 'WEB',
|
|
38
|
+
App: 'CONSUMER_WEB',
|
|
39
|
+
segment: true,
|
|
40
|
+
segmentKey: SEGMENT_KEY,
|
|
41
|
+
debug: true,
|
|
42
|
+
errorHandler: errorHandler,
|
|
43
|
+
rudderstack: {
|
|
44
|
+
enabled: true,
|
|
45
|
+
writeKey: RUDDERSTACK_WRITE_KEY,
|
|
46
|
+
dataPlaneUrl: RUDDERSTACK_DATA_PLANE_URL,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Test function
|
|
51
|
+
async function runTests() {
|
|
52
|
+
console.log('🚀 Initializing analytics...\n');
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
// Initialize analytics
|
|
56
|
+
await analytics.initAnalytics();
|
|
57
|
+
console.log('✅ Analytics initialized successfully\n');
|
|
58
|
+
|
|
59
|
+
// Wait a bit for initialization to complete
|
|
60
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
61
|
+
|
|
62
|
+
console.log('📤 Sending test events...\n');
|
|
63
|
+
|
|
64
|
+
// Test 1: Identify event
|
|
65
|
+
console.log('1️⃣ Sending IDENTIFY event...');
|
|
66
|
+
try {
|
|
67
|
+
await analytics.identify('test-user-123', {
|
|
68
|
+
email: 'test@example.com',
|
|
69
|
+
name: 'Test User',
|
|
70
|
+
testProperty: 'test-value',
|
|
71
|
+
});
|
|
72
|
+
console.log(' ✅ Identify event sent successfully');
|
|
73
|
+
console.log(' 📊 This event should be sent to BOTH Segment and RudderStack\n');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(' ❌ Identify event failed:', error.message);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Wait a bit between events
|
|
79
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
80
|
+
|
|
81
|
+
// Test 2: Test event (track)
|
|
82
|
+
console.log('2️⃣ Sending TEST_EVENT (track)...');
|
|
83
|
+
try {
|
|
84
|
+
// Note: We need to use a valid event name from EVENT_MAP or a generic string
|
|
85
|
+
// Since test_event might not be in EVENT_MAP, we'll use a workaround
|
|
86
|
+
await analytics.track('test_event', {
|
|
87
|
+
testProperty: 'test-value',
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
source: 'rudderstack-test-script',
|
|
90
|
+
});
|
|
91
|
+
console.log(' ✅ Test event sent successfully');
|
|
92
|
+
console.log(' 📊 This event should be sent to BOTH Segment and RudderStack\n');
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(' ❌ Test event failed:', error.message);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Wait a bit for events to be sent
|
|
98
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
99
|
+
|
|
100
|
+
console.log('\n✅ Test completed!');
|
|
101
|
+
console.log('\n📋 Summary:');
|
|
102
|
+
console.log(' - Identify event: Sent to Segment + RudderStack');
|
|
103
|
+
console.log(' - Test event: Sent to Segment + RudderStack');
|
|
104
|
+
console.log('\n🔍 Check your RudderStack dashboard at: http://35.233.238.142');
|
|
105
|
+
console.log(' to verify events were received.\n');
|
|
106
|
+
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('❌ Initialization failed:', error);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Keep process alive for a bit to allow async operations to complete
|
|
113
|
+
setTimeout(() => {
|
|
114
|
+
process.exit(0);
|
|
115
|
+
}, 3000);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Run tests
|
|
119
|
+
runTests().catch((error) => {
|
|
120
|
+
console.error('❌ Test execution failed:', error);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
|
123
|
+
|
package/test-simple.html
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>RudderStack Test - Simple</title>
|
|
6
|
+
<script src="https://unpkg.com/@segment/analytics-next@latest/dist/umd/index.js"></script>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/@rudderstack/analytics-js@latest/dist/npm/index.js"></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<h1>RudderStack Test</h1>
|
|
11
|
+
<button onclick="test()">Run Test</button>
|
|
12
|
+
<pre id="output"></pre>
|
|
13
|
+
<script>
|
|
14
|
+
function log(msg) {
|
|
15
|
+
const output = document.getElementById('output');
|
|
16
|
+
output.textContent += msg + '\n';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function test() {
|
|
20
|
+
log('Starting test...');
|
|
21
|
+
|
|
22
|
+
// This is a simplified test - the actual library needs proper bundling
|
|
23
|
+
log('Note: For full testing, the library needs to be bundled for browser use.');
|
|
24
|
+
log('Please use the Node.js test script or bundle the library with a tool like esbuild/webpack.');
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|