Developers » AS2 tagging » Apple » Content » Custom Object
Custom Object
- iOS
- watchOS
- tvOS
Foreword
The SDK allows the addition of all sorts of information to the stc variable via dictionaries or JSON feeds. Custom objects can be added to any type of tagging, and can then be treated via the Data Manager tool.
Get off to a good start
Once your tag is initialised, you can add your custom objects to your hits.
In the case of a Swift project, be sure to import the Tracker (or tvOSTracker / watchOSTracker if your target is an Apple TV or an Apple Watch) module in your ViewController. In the case of an Objective-C project, be sure to import the headers TrackerSmart-Swift.h or Tracker-Swift.h in case of a Cocoapods integration
Tagging
To add a custom object to your hits, the Screen object exposes object a customObjects property possessing an add method. This method allows for the addition of a custom object that will be added to the next hit sent.
Tagging examples
- Tagging a screen with addition of a “simple” custom object
import UIKit import Tracker class ViewController: UIViewController { let tracker: Tracker = ATInternet.sharedInstance.defaultTracker override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { let screen = tracker.screens.add("Home") screen.customObjects.add(["firstName": "John", "age": 26, "name": "Doe"]) screen.sendView() } }
#import "Tracker/Tracker-Swift.h" @interface ViewController () @property (nonatomic, strong) Tracker* tracker; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.tracker = [ATInternet sharedInstance].defaultTracker; self.tracker.debugger = self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; Screen *screen = [[tracker screens ] add:@"Home"]; [screen.customObjects addDictionary:@{@"firstName": @"John", @"age": @26, @"name": @"Doe"}]; [screen sendView]; } @end
JSON result in stc variable :{ "lifecycle": { "fl": 0, "fld": 20151014, "dsfl": 1, "flau": 0, "dslu": 0, "lc": 57, "lcsu": 0, "ldc": 9, "lwc": 57, "lmc": 57 }, "firstName": "John", "age": 26, "name": "Doe" }
- Tagging a screen with addition of a “complex” custom object
import UIKit import Tracker class ViewController: UIViewController { let tracker: Tracker = ATInternet.sharedInstance.defaultTracker override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { let screen = tracker.screens.add("Home") _ = screen.customObjects.add(["user" : ["language": "en", "country": "US", "currency" : "USD"]]) screen.sendView() } }
#import "ViewController.h" #import "Tracker/Tracker-Swift.h" @interface ViewController () @property (nonatomic, strong) Tracker* tracker; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.tracker = [ATInternet sharedInstance].defaultTracker; self.tracker.debugger = self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; Screen *screen = [[tracker screens ] add:@"Home"]; [screen.customObjects addDictionary:@{@"user": @{@"language": @"en", @"country": @"US", @"currency": @"USD"}}]; [screen sendView]; } @end
JSON result in stc variable :{ "lifecycle": { "fl": 0, "fld": 20151014, "dsfl": 1, "flau": 0, "dslu": 0, "lc": 58, "lcsu": 0, "ldc": 10, "lwc": 58, "lmc": 58 }, "user": { "language": "en", "currency": "USD", "country": "US" } }
- Tagging navigation with the addition of a custom object
import UIKit import Tracker class ViewController: UIViewController { let tracker: Tracker = ATInternet.sharedInstance.defaultTracker override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { let gesture = tracker.gestures.add("Navigate Home") gesture.customObjects.add(["user" : ["language": "en", "country": "US", "currency" : "USD"]]) gesture.sendNavigation() } }
#import "ViewController.h" #import "Tracker/Tracker-Swift.h" @interface ViewController () @property (nonatomic, strong) Tracker* tracker; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.tracker = [ATInternet sharedInstance].defaultTracker; self.tracker.debugger = self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; Gesture *gesture = [[tracker gestures] add:@"Navigate Home"]; [gesture.customObjects addDictionary:@{@"user": @{@"language": @"en", @"country": @"US", @"currency": @"USD"}}]; [gesture sendNavigation]; } @end
- Tagging an ad with the addition of a custom object
import UIKit import Tracker class ViewController: UIViewController { let tracker: Tracker = ATInternet.sharedInstance.defaultTracker override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_ animated: Bool) { let screen = tracker.screens.add() _ = screen.customObjects.add(["user" : ["language": "en", "country": "US", "currency" : "USD"]]) _ = screen.publishers.add("[ad1]") screen.sendView() } }
#import "ViewController.h" #import "Tracker/Tracker-Swift.h" @interface ViewController () @property (nonatomic, strong) Tracker* tracker; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.tracker = [ATInternet sharedInstance].defaultTracker; self.tracker.debugger = self; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; Screen *screen = [[tracker screens] add]; [screen.customObjects addDictionary:@{@"user": @{@"language": @"en", @"country": @"US", @"currency": @"USD"}}]; [screen.publishers add:@"[ad1]"]; [screen sendView]; } @end
CustomObject class
Properties
Name | Type | Default value | Description |
---|---|---|---|
json | String | {} | Gets or sets the object in JSON format |