Local Logic Tracking Library
The Tracking library provides a JavaScript entry point to post events to Local Logic's tracking pipeline.
Installation
Npm:
npm install @local-logic/tracking
Yarn:
yarn add @local-logic/tracking
Pnpm:
pnpm add @local-logic/tracking
Getting Started
To use the library, start by creating a new instance by invoking LocalLogicTracking
with your apiKey
. You can generate a apiKey using the locallogic.co/oauth/apiKey
API.
Example:
import LocalLogicTracking from "@local-logic/tracking";
...
const client = LocalLogicTracking("<apiKey>");
try {
sdkEventLoad = await client.postEvent({
"event_type": "LC-Viewed", // Use one from the Events list
"event_version": "1.0.0",
"meta": {
"product_name": "local-content", // Use one from the Producst list
},
"attributes": {},
});
} catch (e) {
// Handle error
}
Event types
The events need to be one from the next list.
Event type | Description |
---|---|
LC-Viewed | Loading Local Content |
LC-Category-Clicked | Local Content Category Clicked |
LC-Score-Clicked | Local Content Score Clicked |
LC-Long-Description-Clicked | Local Content Long Description Viewed |
LC-POI-Clicked | Local Content POI Clicked |
LC-Commute-Calc-Clicked | Local Content Commute Calc Clicked |
Event type | Description |
---|---|
LD-Viewed | Loading Local Demographics |
LD-Category-Clicked | Demographics Category Clicked |
Product names
The product name need to be one from the next list.
Event type | Description |
---|---|
local-content | Local Content |
local-demographics | Local Demographics |
LAT | Location Assessment Tool |
Methods
postEvent(params: Payload) => Promise<Payload>
Error Handling
You can catch errors by wrapping your method invocations in try / catch
. You can handle your errors generically, or if you require more granular control you can make use of the provided typeguards isRequestError
and isValidationError
.
Example:
import LocalLogicTracking, {
isRequestError,
isValidationError,
} from "@local-logic/tracking";
try {
// Call method
} catch (e) {
if (isRequestError(e)) {
// Handle request errors
}
if (isValidationError(e)) {
// Handle validation errors
}
// Handle all other errors
}
Typescript
@local-logic/tracking
provides type definitions and typeguards.