Getting Started

Requirements

Setup

This is a walk through of setting up a simple project to use the AudienceStream(http://tealium.com/products/audiencestream/) iOS library.

1. Clone Library

Clone or download the library repo onto your dev machine by clicking on the Clone to Desktop or Download ZIP buttons on the main repo page.

2. Add to Project

From the collect-ios/Release folder, drag & drop the TealiumUtilities and TealiumCollect frameworks into your XCode project's Navigation window.

3. Link Frameworks

Link the following Apple framework to your project:

  • SystemConfiguration

4. Add Linker Flags

Add the "-ObjC" linker flag to your project's Target-Build Settings.

5. Import Headers

Objective-C

For Objective-C import the library at the top of any file you wish to access the library in:

#import <TealiumCollect/TealiumCollect.h>

Swift

In swift you'll need to Update your project's Objective-C bridging header or create one with the following entries:

#import <TealiumCollect/TealiumCollect.h>
#import <TealiumCollect/TEALCollectConfiguration.h>
#import <TealiumCollect/TEALVisitorProfile.h>
#import <TealiumCollect/TEALEvent.h>

Enable

Enable the library with a configuration TEALCollectConfiguration instance in your appDelegate class:

Objective-C

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    TEALCollectConfiguration *config = [TEALCollectConfiguration configurationWithAccount:@"tealiummobile"
                                                                                  profile:@"demo"
                                                                              environment:@"dev"];

    config.logLevel = TealiumCollectLogLevelVerbose;

    [TealiumCollect enableWithConfiguration:config];

    return YES;
}

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let configuration = TEALCollectConfiguration(account: "tealiummobile", profile: "demo", environment: "dev")

    configuration.logLevel = TealiumCollectLogLevel.Verbose

    TealiumCollect.enableWithConfiguration(configuration)

    return true
}

Send Action Data

After determining what visitor behaviors should be tracked, utilize the sendEventWithData: method to send link or view events with relevant data to AudienceStream:

Objective-C

- (void) sendLifecycleEventWithName:(NSString *)eventName {

    NSDictionary *data = @{@"event_name" : eventName};

    [TealiumCollect sendEventWithData:data];
}

Swift

func sendLifecycleEventWithName(name: String) {

    let data: [String: String] = ["event_name" : name]

    TealiumCollect.sendEventWithData(data)
}

For more information see Trackable Actions and sendViewWithData:

Fetch Visitor Profile

The TealiumCollect library offers a variety of means to identifiy visitor behavior and offer a personalized app experience via Data layer enrichment from AudienceStream.

Access the enriched Visitor Profile (TEALVisitorProfile) from the Collect ibrary using one of two methods:

First access to the last profile the library received is always available via the cachedVisitorProfileCopy method:

Objective-C

- (void) accessLastLoadedAudienceStreamProfile {

    TEALVisitorProfile *profile = [TealiumCollect cachedVisitorProfileCopy];

    if (profile) {
        NSLog(@"last loaded profile: %@", profile);
    } else {
        NSLog(@"a valid profile has not been received yet.");
    }
}

Swift

func accessLastLoadedAudienceStreamProfile() {

    if let profile:TEALVisitorProfile = TealiumCollect.cachedVisitorProfileCopy() {
        println("last loaded profile: \(profile)")
    } else {
        println("a valid profile has not been received yet.")
    }
}

Second to explicitly fetch a new copy of the user's current profile you can use the fetchVisitorProfileWithCompletion: method. This will query the latest profile and pass the result to the completion block provided:

Objective-C

- (void) fetchAudienceStreamProfile {

    [TealiumCollect fetchVisitorProfileWithCompletion:^(TEALVisitorProfile *profile, NSError *error) {

        if (error) {
            NSLog(@"test app failed to receive profile with error: %@", [error localizedDescription]);
        } else {
            NSLog(@"test app received profile: %@", profile);
        }

    }];
}

Swift

func fetchAudienceStreamProfile() {

    TealiumCollect.fetchVisitorProfileWithCompletion { (profile, error) -> Void in

        if (error != nil) {
            println("test app failed to receive profile with error: \(error.localizedDescription)")
        } else {
            println("test app received profile: \(profile)")
        }
    }
}

For more information see the TEALVisitorProfile class API documentatoin.