0.2.1 • Published 10 months ago

@local-logic/tracking v0.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

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 typeDescription
LC-ViewedLoading Local Content
LC-Category-ClickedLocal Content Category Clicked
LC-Score-ClickedLocal Content Score Clicked
LC-Long-Description-ClickedLocal Content Long Description Viewed
LC-POI-ClickedLocal Content POI Clicked
LC-Commute-Calc-ClickedLocal Content Commute Calc Clicked
Event typeDescription
LD-ViewedLoading Local Demographics
LD-Category-ClickedDemographics Category Clicked

Product names

The product name need to be one from the next list.

Event typeDescription
local-contentLocal Content
local-demographicsLocal Demographics
LATLocation 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.

0.2.1

10 months ago

0.2.0

11 months ago

0.1.1

11 months ago