Tracking Events
Tracking events will be done via functions specific to the event type you wish to track.
import * as pjdwsdk from '@pjdw/analytics-web-sdk';
click() function
Tracks a user click
Signature:export declare function click(label: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The label to associate to the click |
otherAttrs | AdditionalEventData | Additional attributes to send with the event |
void
link() function
Tracks a user opening a link outside of the current domain
Signature:export declare function link(url: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
url | string | |
otherAttrs | AdditionalEventData | Additional attributes to send with the event |
void
submitted() function
Tracks a form submission and it's respective values.
Signature:export declare function submitted(label: string,formVals: any,otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | Tracking form submissions and their values |
formVals | any | object containing the form's values |
otherAttrs | AdditionalEventData | Additional attributes you wish to send with the event |
void
receivedPush() function
Tracks a push notification received by your service worker and displayed to the user. (push
event)
export declare function receivedPush(label: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The label to send with the event |
otherAttrs | AdditionalEventData | Additional attributes to send with the event |
void
openedPush() function
Tracks when a user has opened a push notification. (notificationclick
event)
export declare function openedPush(label: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The label to send with the event |
otherAttrs | AdditionalEventData | Additional attributes to send with the event |
void
viewed() function
Tracks a page/screen view. Page views are automatically tracked by default unless otherwise specified when initializing the SDK.
Signature:export declare function viewed(screenName: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
screenName | string | The name/label you wish to assign to this page |
otherAttrs | AdditionalEventData | Additional attributes you can set |
void
searched() function
Tracks a user searching for something within your website.
Signature:export declare function searched(searchText: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
searchText | string | The text the user searched for |
otherAttrs | AdditionalEventData | Additional attributes you wish to add about the event |
void
purchased() function
Tracks a purchase within your website.
Signature:export declare function purchased(transactionId: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
transactionId | string | The id of the transaction/order |
otherAttrs | AdditionalEventData | Additional attributes you wish to send with the event |
void
authenticated() function
This should be called any time a user **logs in** to your website. This is separate from identify (which should be called whenever your app initializes with an authenticated user, i.e. the authentication token has not expired) and should only be called when the user authenticates/re-authenticates to your website.
Signature:export declare function authenticated(label?: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The label you wish to send with this event |
otherAttrs | AdditionalEventData | Additional attributes you wish to include |
void
loggedOut() function
This should be called any time a user logs out of your website. It will end the current session and start a new session.
Signature:export declare function loggedOut(label?: string, otherAttrs?: AdditionalEventData): void;
Parameters
Parameter | Type | Description |
---|---|---|
label | string | The label you wish to send with this event |
otherAttrs | AdditionalEventData | Additional attributes you wish to include |
void
AdditionalEventData interface
Signature:export interface AdditionalEventData
Properties
Property | Type | Description |
---|---|---|
category? | string | (Optional) A category to assign to this event |
end_time? | Date | (Optional) End time of the event (only applicable for timed events like watching videos and listening to audio) |
meta? | object | (Optional) Additional data you wish to send with the event. Key/value pairs. |
start_time? | Date | (Optional) Start time of the event |