Add Attributes and Events

Add Events and Attributes

After you have collaborated with your marketing analyst to identify the attributes, simple events, and intelligent events you want to use in your campaigns, you need to add them in your code. Follow the procedures below. Attributes and events are described in Before You Begin.

Add Attributes

In your code where you process user information, add the attributes you have identified. The following code snippet provides an example.

var userAttributes= {};
userAttributes["product_purchased"] = product_purchased;

Add Simple Events

For each event you have identified, add the following line in your code where you track the event.


Associate a count and value to an event

You can specify additional count and value information for a purchase-related event you track. For example, if you want to track a user purchase of two items for $5.00 total, you pass 2 for count and 500 for value. The following code snippet provides an example.

Note: Kahuna supports count and value information for purchase-related events only.

Note: This example uses a currency multiplier of 0.01. The currency multiplier is set by Customer Success. You can view the currency multiplier setting for your namespace on the Configuration tab of the Settings page in the Kahuna application.

Kahuna.trackEvent("EVENT_NAME_HERE", withCount:2, andValue:500);

Note: Do not use any delimiter as a thousands separator. For example, use 1234 instead of 1,234 or 1.234.

Add Intelligent Events

For each intelligent event you have identified, instantiate a KahunaEventBuilder object, then call the object's addProperty (key, value) method to add the key and value of the data (this key-value pair is also known as an Intelligent Event property). To create a property that has an array of values, pass each value to addProperty() using the same key.

Note: To use Intelligent Events, you must use Kahuna SDK version 2.2.0 or newer.

Requirements and Limits for Keys and Values
  • Intelligent Event campaign filters ignore the letter case of event names, property keys, and property values. For example, the event WATCH_MOVIE matches the filter value watch_movie, Watch_Movie, and Watch_movie.
  • The property key must be a string value.
  • Property keys cannot start with k_; this prefix is reserved for Kahuna system keys.
  • Property values must be a single string. You can provide a set of values by calling addProperty() multiple times with the same key, passing in a different value each time.
  • You can add up to 25 properties to a single builder object.
  • Because multiple values for a key are stored as a set, you can't add the same value more than once. If you try, you still have one occurrence of that value in the set.
  • If you try to set an empty key or value, addProperty ignores the call and writes a message to the debug logs.

The following code snippet shows you how to add properties for an Intelligent Event using movie genres as an example.

// An EventBuilder that tracks information for a streaming movie app
var watchedEventBuilder = new KahunaEventBuilder("watched_movie");
// Add information about the movie: name, genres, and how long the user watched it
watchedEventBuilder.addProperty("movie_name", "Alien");
watchedEventBuilder.addProperty("genre", "horror");
// The value of "genre" isn't overwritten; instead, it's an array of strings.
watchedEventBuilder.addProperty("genre", "sci-fi");
watchedEventBuilder.addProperty("time_window", "30");

Add Purchase Data

To add purchase data to a KahunaEventBuilder object, add this code.

watchedEventBuilder.setPurchaseData(number_of_movies, total_cost);

Note: Do not use any delimiter as a thousands separator. For example, use 1234 instead of 1,234 or 1.234.

Send Intelligent Events

After you add properties and purchase data to the KahunaEventBuilder object, you can send the event to the Kahuna SDK, which manages the process of transmitting it to the server.

The following code snippet continues the previous snippets by creating the event and passing it to the Kahuna SDK.


You can now use the Intelligent Event in your campaigns.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request