You can use the setExtras
and getExtras
API to pass and retrieve the information.
To use cohorts in Meson UI, this is where you will need to set a PPID unique to a user
To use segments or experiments in Meson UI, this is where you will need to send the segments or experiments.
This is optional. In case you want to send us any information about the user, follow the instructions to set the user data:
Key | Data Type | Value |
---|---|---|
Gender | Int | Use GenderMale = 1 GenderFemale =2 Enum in MesonSDK |
Age | Int | Age of the user |
Segments | Array<String> |
[“High-value”, “Paid”] |
Interests | String | User interest area |
#warning("Call this method to setExtras")
private func setExtras() {
var extraData: [String: Any] = [:]
// You can notify Meson that restricted data processing is enabled using either of the following parameters.
extraData["rdp"] = false
extraData["iab_usprivacy_string"] = "1YNN"
extraData["gender"] = Gender.male.rawValue
extraData["age"] = 18
extraData["segments"] = ["s1","s2","s3"]
extraData["experiments"] = ["e1","e2","e3"]
extraData["interests"] = "<interests>"
Meson.setExtras(extraData)
}
#warning("Call this method to getExtras")
private func getExtras() {
guard let extras = Meson.getExtras() else {
return
}
let genderData = extras["gender"]
}
#warning("Call this method to setExtras")
- (void)setExtras {
NSMutableDictionary *extras = [[NSMutableDictionary alloc] init];
// You can notify Meson that restricted data processing is enabled using either of the following parameters.
[extras setValue:false forKey:@"rdp"];
[extras setValue:@"1YNN" forKey:@"iab_usprivacy_string"];
[extras setValue:@(GenderMale) forKey:@"gender"];
[extras setValue:@(23) forKey:@"age"];
[extras setValue:@"<interests>" forKey:@"interests"];
[extras setValue:@[@"s1",@"s2",@"s3"] forKey:@"segments"];
[extras setValue:@[@"e1",@"e2",@"e3"] forKey:@"experiments"];
[Meson setExtras:extras];
}
#warning("Call this method to getExtras")
- (void)getExtras {
NSDictionary *extras = [Meson getExtras];
NSNumber *genderData = extras[@"gender"];
}
Use the following code to create a MesonExtras.swift file.
import Foundation
struct MesonExtras: Codable {
var age: Int?
var gender: Int?
var interests: String?
var segments: [String]?
var experiments: [String]?
var rdp: Bool?
var iab_usprivacy_string: String?
}
extension MesonExtras {
/// Convert Model to Dictionary
var asDictionary: [String: Any] {
do {
let data = try JSONEncoder().encode(self)
let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
return dictionary ?? [:]
} catch {
return [:]
}
}
/// Convert Dictionary to MesonExtrasModel
static func decode(extras: [String: Any]) throws -> MesonExtras?
{
let data = try JSONSerialization.data(withJSONObject: extras)
return try JSONDecoder().decode(MesonExtras.self, from: data)
}
}
#warning("Call this method to setExtras")
private func setExtras() {
var extras = MesonExtras()
extras.rdp = false
extras.iab_usprivacy_string = "1YNN"
extras.gender = Gender.male.rawValue
extras.age = 23
extras.interests = "cricket"
extras.segments = ["s2","s1"]
Meson.setExtras(extras.asDictionary)
}
#warning("Call this method to getExtras")
private func getExtras() {
guard let extras = Meson.getExtras() else {
return
}
let mesonExtras = try? MesonExtras.decode(extras: extras)
/// Get the model value
_ = mesonExtras?.gender
}
To import Swift into Objective-C, see Apple's Documentation.
import Foundation
@objcMembers
@objc public class MesonExtras: NSObject, Codable {
public var age: Int
public var gender: Int
public var interests: String?
public var segments: [String]?
public var experiments: [String]?
public var rdp: Bool
public var iab_usprivacy_string: String?
}
@objc extension MesonExtras {
/// Convert Model to Dictionary
var asDictionary: [String: Any] {
do {
let data = try JSONEncoder().encode(self)
let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
return dictionary ?? [:]
} catch {
return [:]
}
}
/// Convert Dictionary to MesonExtrasModel
static func decode(extras: [String: Any]) -> MesonExtras? {
do {
let data = try JSONSerialization.data(withJSONObject: extras)
return try JSONDecoder().decode(MesonExtras.self, from: data)
} catch {
return nil
}
}
}
#warning("Call this method to setExtras")
- (void)setExtras {
MesonExtras *extras = [[MesonExtras alloc] init];
// You can notify Meson that restricted data processing is enabled using either of the following parameters.
extras.rdp = FALSE;
extras.iab_usprivacy_string = @"1YNN";
extras.gender = GenderMale;
extras.age = 23;
extras.interests = @"cricket";
extras.segments = @[@"s2",@"s1"];
[Meson setExtras:[extras asDictionary]];
}
#warning("Call this method to getExtras")
- (void)getExtras {
NSDictionary *extras = [Meson getExtras];
if (extras == nil) {
return;
}
MesonExtras *mesonExtras = [MesonExtras decodeWithExtras:extras];
NSInteger genderData = mesonExtras.gender;
NSLog(@"%ld",(long)genderData);
}
To use cohorts, segments, or experiments on Meson UI, you must set the PPID unique to a user.
#warning("Call this method to setPPId")
private func setPPId() {
Meson.setPPID("ppid_value")
/// Getter for PPID
//let ppidValue = Meson.getPPID()
}
#warning("Call this method to setPPId")
- (void)setPPId {
[Meson setPPID:@"ppid_value"];
//
// // Getter for PPID
// NSString *ppidValue = [Meson getPPID];
}
If your app collects location from the user, we recommend passing it up, as impressions with location signals have higher revenue potential.
To seek location permission, you can set NSLocationWhenInUseUsageDescription
flag in your info.plist
file. For more information, see Core Location.
import CoreLocation
import MesonSDK
@main
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
.
.
.
.
var locationMgr: CLLocationManager?
#warning(" Call this method to request For Location")
private func requestForLocation() {
locationMgr = CLLocationManager()
locationMgr?.requestWhenInUseAuthorization()
locationMgr?.delegate = self
locationMgr?.startUpdatingLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let clLocation = locations.last {
Meson.setLocation(clLocation)
}
locationMgr?.stopUpdatingLocation()
}
}
#import "AppDelegate.h"
@import MesonSDK;
@import CoreLocation;
@interface AppDelegate () <CLLocationManagerDelegate>
@property(nonatomic, strong) CLLocationManager *locationMgr;
@end
@implementation AppDelegate
.
.
.
.
#warning("Call this method to request For Location")
- (void)requestForLocation {
self.locationMgr = [[CLLocationManager alloc] init];
[self.locationMgr requestWhenInUseAuthorization];
self.locationMgr.desiredAccuracy = kCLLocationAccuracyHundredMeters;
self.locationMgr.delegate = self;
[self.locationMgr startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *clLocation = locations.lastObject;
[Meson setLocation:clLocation];
[self.locationMgr stopUpdatingLocation];
}
@end
It deletes the following data from persistent storage (Location, Extras, PPID, Gender).
#warning("Call this method to clear User Data set by you")
private func clearUserData() {
Meson.cleanUserInfo()
}