Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Level 2s 43d787

Benjamin Diolez edited this page May 5, 2026 · 1 revision

Data collection / Apple / Content / Level 2s

Foreword

AT Internet�s SDK offers you the possibility to �separate� your application into different sections (called �level 2s�). These level 2s allow you to better target certain parts of your application in order to zoom in on how these parts are used.

Get off to a good start

Once your tag is initialised, you can modify the level 2 ID used in the sending of hits.

In the case of a Swift project, be sure to import the Tracker (or TrackerExtension if your target is an extension) module in your ViewController. In the case of an Objective-C project, be sure to import the headers Tracker-Swift.h or Tracker-Swift.h in case of a Cocoapods integration.

Tagging

The SDK allows you to modify the level 2 ID that will be sent during a screen hit, a gesture hit You Can also modify the level 2 ID in a more �global� manner for permanent use.

The tracker possesses a context property which itself possesses a level2 subproperty. By default, this property is 0. By editing this property�s value, the level 2 ID will be added in to future hits.

To disable this feature, simply reset the ID to 0.

Tagging examples

In these examples, we�ll consider the addition of level 2 information on screen tagging.

  1. Setup of a level 2 when a user enters a particular section of the app

override func viewWillAppear(animated: Bool) {
    ATInternet.sharedInstance.defaultTracker.context.level2 = 1
    ATInternet.sharedInstance.defaultTracker.screens.add("home").sendView()
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [ATInternet sharedInstance].defaultTracker.context.level2 = 1;
    [[[ATInternet sharedInstance].defaultTracker.screens add:@"home"] sendView];
}
  1. Delete tracker�s level 2 by default when screen is changed

override func viewWillDisappear(animated: Bool) {
    ATInternet.sharedInstance.defaultTracker.context.level2 = 0
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [ATInternet sharedInstance].defaultTracker.context.level2 = 0;
}
  1. Override a level 2 for a hit

import UIKit
import Tracker

class ViewController: UIViewController {
    let tracker: Tracker = ATInternet.sharedInstance.defaultTracker
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewWillAppear(animated: Bool) {
        // Set level 2 ID for next hits
        tracker.context.level2 = 1
        tracker.screens.add("home").sendView()
    }

    @IBAction func touchButton(sender: UIButton) {
        let touch = tracker.gestures.add("ButtonTouch")
        touch.level2 = 2 // Override level 2 ID for this hit
        touch.sendTouch()
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Level 2 ID will be equal to "1"
        tracker.gestures.add("Go to product detail").sendNavigation()
    }
}
#import "Tracker/Tracker-Swift.h"

@interface ViewController ()
@property (nonatomic, strong) Tracker* tracker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tracker = [ATInternet sharedInstance].defaultTracker;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // Set level 2 ID for next hits
    self.tracker.context.level2 = 1;
    [[self.tracker.screens add:@"home"] sendView];
}

- (IBAction)touchButton:(UIButton *)sender {
    Gesture *touch = [self.tracker.gestures add:@"ButtonTouch"];
    touch.level2 = 2; // Override level 2 for this hit
    [touch sendTouch];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Level 2 ID will be equal to "1"
    [[self.tracker.gestures add:@"Go to product detail"] sendNavigation];
}

@end

Wiki contents

Clone this wiki locally