Localisation

  • iOS
  • watchOS
  • tvOS
 

Foreword

If you collect and/or use your users’ geolocalisation data, you must inform these users of this data collection, the purpose of its treatment, and any possible data transfers to third parties. You must obtain the consent of the user and provide him/her the means of refusing collection and treatment of this data. You must also declare to the qualified authorities in your country that you are using localisation data in your analyses. If this data can be cross-matched with nominative personal data (measuring identified visitors with imported visitor indicators and DataExplorer subscription), you must also declare to these authorities the exact nature of the cross-matchable data.

You can add geolocalisation data (latitude, longitude) in a screen hit.

Only the two first digits after the decimal separator will be taken into account.

 

Get off to a good start

Once your tag is initialised, you can add geolocalisation data to your screen 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 header SmartTracker-Swift.h

 

Tagging examples

  1. Tagging a screen with geolocalisation data

    import UIKit
    import SmartTracker
    
    class ViewController: UIViewController {
        let tracker = ATInternet.sharedInstance.defaultTracker
        
        override func viewDidLoad() {
            super.viewDidLoad()
        }
        
        override func viewWillAppear(animated: Bool) {
            let screen = tracker.screens.add("Map")
            screen.location = Location(-21.03, longitude: 177.91)
            screen.sendView()
        }
    }
    #import "ViewController.h"
    #import "SmartTracker/SmartTracker-Swift.h"
    
    @interface ViewController ()
    @property (nonatomic, strong) Tracker *tracker;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.tracker = [ATInternet sharedInstance].defaultTracker;
        Screen *screen = [self.tracker screens] add:@"Map"];
        screen.location = [[Location alloc] initWithLatitude:-21.03 longitude:177.91];
        [screen sendView];
    }
    
    @end
  2. Tagging a screen with geolocalisation data and use of dispatcher

    import UIKit
    import Tracker
    
    class ViewController: UIViewController {
        let tracker = ATInternet.sharedInstance.defaultTracker
        
        override func viewDidLoad() {
            super.viewDidLoad()
        }
        
        override func viewWillAppear(animated: Bool) {
            // Track a screen with name Map
            let mapScreen = tracker.screens.add("Map")
            // Add location to screen hit
            mapScreen.location = Location(-21.03, longitude: 177.91)
            // Add a custom object 
            mapScreen.customObjects.add(["country":"fr"]) 
            // Add a custom variable 
            mapScreen.customVars.add(1, value: "fr", type: CustomVar.CustomVarType.Screen)
            // Set a level2 ID
            mapScreen.level2 = 1 
            // Send screen hit
            tracker.dispatch()
        }
    }
    #import "ViewController.h"
    #import "SmartTracker/SmartTracker-Swift.h"
    
    @interface ViewController ()
    @property (nonatomic, strong) Tracker *tracker;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.tracker = [ATInternet sharedInstance].defaultTracker;
        // Track a screen with name Map
        Screen *screen = [[tracker screens ] add:@"Map"];
        // Add location to next screen hit
        screen.location = [[Location alloc] initWithLatitude:-21.03 longitude:177.91];
        // Add a custom object
        [screen.customObjects addDictionary:@{@"country":@"fr"}];
        // Add a custom variable
        [screen.customVars add:1 value:@"fr" type:CustomVarTypeScreen];
        screen.level2 = 1;
        // Send screen hit
        [screen sendView];
    }
    
    @end
 

Location class

 

Properties

Name Type Default value Description
latitude Double 0.0 Gets or sets latitude
longitude Double 0.0 Gets or sets longitude
 

Was this post helpful?

Last update: 13/12/2016