Skip to content

iOS User Tagging Example

You can tag users/devices from your SDK in one line of code.

The SDK looks after the details for the device, you just supply the tag key and value:

  • The tag name (key) is what you want to call it. In the example below "Plan-49" is how you will see this in the Contextual Dashboard.
  • Contextual supports tags of: string, numeric and datetime. In the example below, the value for "Plan-49" is "Trial-Period".

See the API Reference -> Tagging for more detail.

Examples

String Tags

Swift 
1
Contextual.sharedInstance().tagString("Trial-Period", forKey: "Plan-49")
Objc 
1
[CONTEXTUAL tagString:@"Trial-Period" forKey:@"Plan-49"];

Numeric Tags

Swift 
1
Contextual.sharedInstance().tagNumeric(549, forKey: ""BidValue"")
Objc 
1
[CONTEXTUAL tagNumeric:549 forKey:@"BidValue"];

Datetime Tags

Swift 
1
2
3
4
5
6
7
8
9
// Tagging using predefined Contextual tag.
let key = "sh_registered"
let datetime_value = NSDate()
Contextual.sharedInstance().tagDatetime(datetime_value, forKey: key)

// Tagging using custom tag
let key = "Birthday"
let datetime_value = NSDate()
Contextual.sharedInstance().tagDatetime(datetime_value, forKey: key) // string Date time value in UTC
Objc 
1
2
3
4
5
6
7
8
9
// Tagging using predefined Contextual tag.
NSString *key = @"sh_registered";
NSDate *datetime_value = [NSDate date];
[CONTEXTUAL tagDatetime:datetime_value forKey:key];

// Tagging using custom tag.
NSString *key = @"Birthday";
NSDate *datetime_value = [NSDate date];
[CONTEXTUAL tagDatetime:datetime_value forKey:key]; // string Date time value in UTC

Increment Tag Value

Swift 
1
2
let key = "PageVisited"
Contextual.sharedInstance().incrementTag(key)
Objc 
1
2
NSString *key = @"PageVisited";
[CONTEXTUAL incrementTag:key];

Remove Tag

Swift 
1
2
let key = "RemoveUser"
Contextual.sharedInstance().removeTag(key)
Objc 
1
2
NSString *key = @"RemoveUser";
[CONTEXTUAL removeTag:key];

Last update: 2024-01-30