What is @snowplow/browser-tracker-core?
@snowplow/browser-tracker-core is a core library for Snowplow's browser tracking. It provides the essential functionalities to track user interactions and events on web pages, enabling detailed analytics and insights.
What are @snowplow/browser-tracker-core's main functionalities?
Initialize Tracker
This feature allows you to initialize a new Snowplow tracker instance. You need to provide a tracker namespace, the collector endpoint, and optional configuration settings such as the application ID.
const { newTracker } = require('@snowplow/browser-tracker-core');
const tracker = newTracker('sp1', 'my-collector.com', { appId: 'my-app-id' });
Track Page View
This feature enables tracking of page views. It sends an event to the collector whenever a page is viewed, which is essential for understanding user navigation and engagement.
tracker.trackPageView();
Track Custom Events
This feature allows you to track custom events by defining a self-describing event schema and data. It is useful for capturing specific user interactions that are not covered by standard event types.
tracker.trackSelfDescribingEvent({
schema: 'iglu:com.acme/event/jsonschema/1-0-0',
data: {
eventCategory: 'category',
eventAction: 'action',
eventLabel: 'label',
eventValue: 'value'
}
});
Track Structured Events
This feature enables tracking of structured events, which are predefined event types with specific properties. It is useful for capturing common user interactions like clicks, form submissions, and more.
tracker.trackStructEvent({
category: 'category',
action: 'action',
label: 'label',
property: 'property',
value: 'value'
});
Other packages similar to @snowplow/browser-tracker-core
google-analytics
Google Analytics is a widely-used web analytics service that tracks and reports website traffic. It offers similar functionalities to @snowplow/browser-tracker-core, such as tracking page views, custom events, and user interactions. However, Google Analytics is a hosted service with a different data ownership model compared to Snowplow, which allows for more control over data.
mixpanel-browser
Mixpanel is an advanced analytics platform that focuses on tracking user interactions and engagement. The mixpanel-browser package provides functionalities similar to @snowplow/browser-tracker-core, including tracking events and user properties. Mixpanel also offers powerful segmentation and analysis tools, but it is a hosted service with different pricing and data control compared to Snowplow.
Snowplow Browser Tracker Core
Browser Core module to be used by Snowplow Browser based trackers.
It should rarely be used alone, you probably want @snowplow/browser-tracker
.
Maintainer quick start
Part of the Snowplow JavaScript Tracker monorepo.
Build with Node.js (12 LTS or 14 LTS) and Rush.
Setup repository
npm install -g @microsoft/rush
git clone https://github.com/snowplow/snowplow-javascript-tracker.git
rush update
Building Browser Tracker Core
cd libraries/browser-tracker-core
rushx build
Running tests
rushx test
Package Installation
With npm:
npm install @snowplow/browser-tracker-core
Usage
import { addTracker, createSharedState, getTracker } from '@snowplow/browser-tracker-core';
const sharedState = createSharedState();
const tracker = addTracker('snowplow_sp1', 'sp1', 'js-3.0.0', '{{collector}}', sharedState, {});
const sameTracker = getTracker('snowplow_sp1');
Example
const domainUserId = tracker.getDomainUserId();
Other features
This package contains a number of helper functions for tracking events in the browser as well as the core functionality of the Snowplow JavaScript Tracker.
Copyright and license
Licensed and distributed under the BSD 3-Clause License (An OSI Approved License).
Copyright (c) 2021 Snowplow Analytics Ltd, 2010 Anthon Pang.
All rights reserved.