UNPKG

thrivestack-analytics

Version:

ThriveStack Analytics - Privacy-first web analytics for Node.js and browsers

86 lines (85 loc) 3.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThriveStack = void 0; const Thrivestack_1 = require("./core/Thrivestack"); Object.defineProperty(exports, "ThriveStack", { enumerable: true, get: function () { return Thrivestack_1.ThriveStack; } }); // Example usage of ThriveStack Node.js library function main() { return __awaiter(this, void 0, void 0, function* () { // Initialize ThriveStack with your API key and source const analytics = new Thrivestack_1.ThriveStack({ apiKey: 'your-api-key-here', source: 'your-source-id', trackClicks: false, // Not applicable in Node.js trackForms: false, // Not applicable in Node.js enableConsent: false, // Disable consent for server-side tracking batchSize: 10, batchInterval: 2000 }); try { // Initialize the analytics yield analytics.init(); console.log('ThriveStack initialized successfully'); // Set user information yield analytics.setUser('user123', 'user@example.com', { name: 'John Doe', plan: 'premium' }); // Set group information yield analytics.setGroup('group456', 'example.com', 'Example Corp', { industry: 'technology', size: 'medium' }); // Capture a page visit (adapted for Node.js) yield analytics.capturePageVisit({ title: 'API Dashboard', url: 'https://api.example.com/dashboard', path: '/dashboard', referrer: 'https://example.com' }); // Capture custom events yield analytics.captureEvent('user_login', { login_method: 'email', success: true }); yield analytics.captureEvent('api_request', { endpoint: '/api/users', method: 'GET', response_time: 150, status_code: 200 }); // Enable debug mode to see what's being sent analytics.enableDebugMode(); // Capture another event to see debug output yield analytics.captureEvent('debug_test', { message: 'This is a test event' }); // Get interaction history const history = analytics.getInteractionHistory(); console.log('Interaction history:', history); // Get device ID const deviceId = analytics.getDeviceId(); console.log('Device ID:', deviceId); // Get location info const locationInfo = analytics.getLocationInfo(); console.log('Location info:', locationInfo); // Get IP address const ipAddress = analytics.getIpAddress(); console.log('IP Address:', ipAddress); } catch (error) { console.error('Error using ThriveStack:', error); } }); } // Run the example main().catch(console.error);