You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@canonical/analytics-events

Package Overview
Dependencies
Maintainers
25
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@canonical/analytics-events - npm Package Compare versions

Comparing version
1.0.3
to
1.0.4
+1
dist/types/events/pageView.d.ts
export declare function trackPageView(target: string): void;
+17
-2

@@ -226,2 +226,15 @@ // src/session.ts

// src/events/pageView.ts
function trackPageView(target) {
try {
const element = document.createElement("div");
element.dataset.analyticsTarget = target;
enqueue({
element,
eventType: "page_view"
});
} catch {
}
}
// src/events/view.ts

@@ -342,7 +355,9 @@ var DEFAULT_VISIBILITY_THRESHOLD = 0.75;

window.Analytics = {
init: initAnalytics
init: initAnalytics,
trackPageView
};
}
export {
initAnalytics
initAnalytics,
trackPageView
};

@@ -0,3 +1,5 @@

import { trackPageView } from "./events/pageView";
import type { AnalyticsOptions } from "./types";
import "./types";
export declare function initAnalytics({ appName, endpoint }: AnalyticsOptions): void;
export { trackPageView };
+2
-1

@@ -5,2 +5,3 @@ declare global {

init: (options: AnalyticsOptions) => void;
trackPageView: (target: string) => void;
};

@@ -13,3 +14,3 @@ }

}
export type EventType = "click" | "hover" | "view";
export type EventType = "click" | "hover" | "view" | "page_view";
export interface RawEvent {

@@ -16,0 +17,0 @@ eventType: EventType;

{
"name": "@canonical/analytics-events",
"version": "1.0.3",
"version": "1.0.4",
"description": "Lightweight analytics event tracking",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -10,2 +10,3 @@ # Analytics Events

- View tracking (fires after 5s visibility at 75% threshold)
- Page view tracking (fires immediately, no threshold)
- Session tracking via sessionStorage (persists across page reloads)

@@ -37,3 +38,4 @@ - Event batching (10 events or 10s timeout, flushes on page hide)

<script type="module">
import { initAnalytics } from '@canonical/analytics-events';
import { initAnalytics, trackPageView } from '@canonical/analytics-events';
initAnalytics({

@@ -43,2 +45,5 @@ appName: 'snapcraft',

});
// Track a page view immediately (no threshold or observer)
trackPageView('snap_details_page');
</script>

@@ -58,2 +63,21 @@ ```

### API
#### `initAnalytics(options)`
Initializes all declarative tracking (click, hover, view) and configures the sender.
| Option | Type | Description |
|--------|------|-------------|
| `appName` | `string` | Application identifier (e.g. `"snapcraft"`) |
| `endpoint` | `string` | URL to send event batches to |
#### `trackPageView(target)`
Fires a `page_view` event immediately. Use this for tracking page visits where you need every visit counted regardless of how quickly the user navigates away.
| Parameter | Type | Description |
|-----------|------|-------------|
| `target` | `string` | Identifier for the page (e.g. `"snap_details_page"`) |
### Payload Structure

@@ -66,3 +90,3 @@

{
event_type: "click" | "hover" | "view",
event_type: "click" | "hover" | "view" | "page_view",
session_id: "session_abc123...",

@@ -69,0 +93,0 @@ target: "signup_btn",