# # #

#

Usage

Initialization

Initialize the TrackZeroClient instance by passing in your API key before using any of the methods.

var instance = new TrackZeroClient("API-KEY");

Getting Started

TrackZero Instance

After initializing the TrackZero instance, you could get the instance anywhere in your project

var instance = TrackZeroClient.getInstance();

Entity

Entities are objects that contain data. It can represent any object in the real world. Each entity is defined by it’s Type and Id.

Create an Entity object

///Initializes the Entity object
///
///[type] - Entity's type
///[id] - {String | int} - Entity's id

Entity entity = new Entity("type", "id");

Add Attributes

///Adds custom attributes to the entity
///
///[attribute] - Entity's attribute name
///[value] - Entity's attribute value

entity.addAttribute("attribute", "value");

Add Attributes Referencing Other Entities

///Adds custom attributes to the entity that are related to another entity
///
///[attribute] - Entity's attribute name
///[referenceType] - Related to entity type
///[referenceId] - {String | int} - Related to entity id

entity.addEntityReferencedAttribute(
  "attribute",
  "referenceType",
  "referenceId"
);

Track Entity

///Creates/Updates the Entity
await instance.upsertEntity(entity);

Note: Upsert (Update/Insert) is applied when sending the entity. So, if the the entity of type X with id Y already exists, then it gets updated, else a new entity is created. This also applies to the entity's referenced attributes in addEntityReferencedAttribute.

Complete Entity Example

Entity user = new Entity("User", "USER_ID")
  .addAttribute("Name", "Sam Smith")
  .addAttribute("Date Of Birth", DateTime.utc(1990, 12, 23).toIso8601String()) //Make sure dates are in ISO8601 String
  .addEntityReferencedAttribute("Location", "Country", "US");

await instance.upsertEntity(user);

Delete Entity

:warning:   Deleting an entity will delete all events emitted by this entity.

:exclamation:   Deletion is permanent and cannot be undone.

///Deletes the Entity
///
///[type] - type of entity to be deleted
///[id] - {String | int} - id of the entity to be deleted

await instance.deleteEntity("type", "id");

Event

Events are considered as actions that are emitted from an entity and impact another entity

Create an Event object

///Initializes the Event object
///
///[emitterType] - the entity type that emitted the event
///[emitterId] - {String | int} - the entity id that emitted the event
///[name] - the event name
///
///_OPTIONAL PARAMS_
///
///[id] - {String | int} - the event id.
///[startTime] - (ISO 8601) The start time of the event.
///[endTime] - (ISO 8601) The end time of the event.

Event event = new Event(
  "emitterType",
  "emitterId",
  "name",
  ["id",
  "startTime",
  "endTime"]
);

Note: startTime and endTime are important, always try to set them. If both are not supplied, both will be set to the current time. If one is not supplied, it will be set to be equal to the other.

Note: The id of the event is important if you plan on changing or adding more information to the event later. You will need the id to make those changes.

Add Attributes

///Adds custom attributes to the event
///
///[attribute] - Event's attribute name
///[value] - Event's attribute value

event.addAttribute("attribute", "value");

Add Attributes Referencing Other Entities

///Adds custom attributes to the event that are related to another entity
///
///[attribute] - Event's attribute name
///[referenceType] - Related to entity type
///[referenceId] - {String | int} - Related to entity id

event.addEntityReferencedAttribute("attribute", "referenceType", "referenceId");

Add Impacted Entities

///Adds entities that were impacted by this event
///
///[impactedType] - Entity type that was impacted
///[impactedId] - Entity Id that was impacted

event.addImpactedTarget("impactedType", "impactedId");

Track Event

///Creates/Updates the Event
await instance.upsertEvent(event);

Note: Like the Entity object, upsert (Update/Insert) is applied to the event's emitter, entity's referenced attributes in addEntityReferencedAttribute, and the impacted entities in addImpactedTarget.

Complete Event Example

Event checked = new Event("User", "USER_ID", "Checked Out")
  .addAttribute("Cart Total", 99.95)
  .addEntityReferencedAttribute("Item", "Product", "SKU-1234")
  .addImpactedTarget("Warehouse", "WH-BLVD-652");

await instance.upsertEvent(checked);

Delete Event

:exclamation:   Deletion is permanent and cannot be undone.

///Deletes the Event
///
///[type] - event type/name to be deleted
///[id] - {String | int} - id of the event to be deleted

await instance.deleteEvent("type", "id");

Resources

Changelog

License

MIT

Libraries

leiratech_trackzero