Store Attribute based on an EventUpdated 21/04/2020

Events are great for tracking user's interactions with different tools. They are also useful to trigger actions, but if they carry important information about user lifecycle, then it's usually better to capture that information as attributes.

While events expire after the retention period attributes are stored indefinitely. This is also a good way to aggregate data from multiple occurences of an event.

Snippet below shows how you can write set of different attributes on the User profile when a specific event is detected.

// Loop over each event in this batch => {
  // If the right even happens
  if (e.event === "Trial Started") {
    // Get some details about the event
    const { trial_plan } =;
    // Set traits on the User
      "trial/started": true, // boolean indicating that event happened at least once
      "trial/first_at": { operation: "setIfNull", value: e.created_at }, // timestamp of the first occurence of the event
      "trial/last_at": e.created_at, // timestamp of the last occurence of the event
      "trial/last_plan": trial_plan, // details from the last occurence of the event
      "trial/count": { operation: "inc", value: 1 } // counter