TAGDataLayer Class Reference

TAGDataLayer Class Reference

Overview

The data layer is a dictionary holding generic information about the application.

It uses a standard set of keys so it can be read by any party that understands the specification. The data layer state is updated through its API. For example, an app might start with the following dataLayer:

   {
     title: "Original screen title"
   }

As the state/data of an app can change, the app can update the dataLayer with a call such as:

   [dataLayer push:@{@"title": @"New screen title"}];

Now the data layer contains:

   {
     title: "New screen title"
   }

After another push happens:

   [dataLayer push:@{@"xyz": @3}];

The dataLayer contains:

   {
     "title": "New screen title",
     "xyz": 3
   }

The following example demonstrates how array and map merging works. If the original dataLayer contains:

   {
     "items": @[@"item1", [NSNull null], @"item2", @{@"a": @"aValue", @"b": @"bValue"}]
   }

After this push happens:

   [dataLayer push:@{@"items":
       @[[NSNull null], @"item6", kTAGDataLayerObjectNotPresent, @{@"a": [NSNull null]}]}

The dataLayer contains:

   {
     "items": @[[NSNull null], @"item6", @"item2", @{@"a": [NSNull null], @"b": @"bValue"}]}
   }

Pushes happen synchronously; after the push, changes have been reflected in the model.

When an event key is pushed to the data layer, rules for tags are evaluated and any tags matching this event will fire. For example, given a container with a tag whose firing rules is that "event" is equal to "openScreen", after this push:

   [dataLayer push:@{@"event", @"openScreen"}];

that tag will fire.

Public Member Functions

(void) - pushValue:forKey:
 Pushes a key/value pair to the data layer.
(void) - push:
 Merges the given update object into the existing data model, calling any listeners with the update (after the merge occurs).
(NSObject *) - get:
 Returns the object in the model associated with the given key.

Member Function Documentation

- (void) pushValue: (NSObject *)  value
forKey: (NSObject *)  key 

Pushes a key/value pair to the data layer.

This is just a convenience method that calls push:@{key: value}.

- (void) push: (NSDictionary *)  update

Merges the given update object into the existing data model, calling any listeners with the update (after the merge occurs).

It's valid for values in the dictionary (or embedded Arrays) to be of type NSNull. If you want to represent a missing value (like an empty index in a List), use the kTAGDataLayerObjectNotPresent object.

This is normally a synchronous call. However, if, while the thread is executing the push, another push happens from the same thread, then that second push is asynchronous (the second push will return before changes have been made to the data layer). This second push from the same thread can occur, for example, if a data layer push is made in response to a tag firing. However, all updates will be processed before the outermost push returns.

If the update contains the key event, rules will be evaluated and matching tags will fire.

Parameters:
updateThe update object to process
- (NSObject*) get: (NSString *)  key

Returns the object in the model associated with the given key.

If key isn't present, returns nil. If key is present, but NSNull, returns NSNull.

The key can can have embedded periods. For example: a key of "a.b.c" returns the value of the "c" key in the dictionary with key "b" in the dictionary with key "a" in the model.