Add Attributes and Events

Add Attributes and Events

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.

NSDictionary *userAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
          @"John", @"first_name", // User's first name
          @"Q", @"last_name", // User's last name
          @"m", @"gender", // User's gender
          [NSNumber numberWithInt:1], @"birth_day", // User's birth day
          [NSNumber numberWithInt:1], @"birth_month", // User's birth month
          [NSNumber numberWithInt:1989], @"birth_year", // User's birth year

[Kahuna setUserAttributes:userAttributes];

Add Simple Events


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

KAHEventBuilder *watchedEventBuilder = [KAHEventBuilder eventWithName:@"event_name"];


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.

[watchedEventBuilder setPurchaseCount:2 andPurchaseValue: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 KAHEventBuilder 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_, because 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 snippets show you how to add properties for an Intelligent Event, using movie genres as an example.

#import <Kahuna/Kahuna.h>
// A KAHEventBuilder object that tracks information for a streaming movie app
KAHEventBuilder *watchedEventBuilder = [KAHEventBuilder eventWithName:@"watched_movie"];
// Add information about the movie: name, genres, and how long the user watched it
[watchedEventBuilder addProperty:@"name" withValue:@"Alien"];
[watchedEventBuilder addProperty:@"genre" withValue:@"sci-fi"];
// The value of "genre" is not overwritten; instead, it is an array of strings
[watchedEventBuilder addProperty:@"genre" withValue:@"horror"];
[watchedEventBuilder addProperty:@"time_window" withValue:@"30"];

Note: Although you can use both upper and lower case in your custom data, Intelligent Event campaign filters ignore case.

Add Purchase Data

To add purchase data to a KAHEventBuilder object:

[watchedEventBuilder setPurchaseCount:number_of_movies andPurchaseValue: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 KAHEventBuilder object, you can send the Intelligent 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 SDK.

[Kahuna track:[watchedEventBuilder build]];

You can now use the Intelligent Event in your campaigns.

Next, follow the steps in Set Up Location Monitoring.

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