SDK Objects

The SDK consists of the following classes.

Personalization Class

Personalization is the main class. You can use an instance of this to invoke the different methods of SDK.

import Foundation
import monetate_ios_sdk

Create an instance of this class using the following code:

final var personalization = Personalization(account: Account(instance: "p", domain: "localhost.org", name: "a-701b337c", shortname: "localhost"), user: User(monetateId: "2.1454546575.1711006580023", deviceId: "62bd2e2d-213d-463f-83bb-12c0b2530a14", customerId: "12345")) 

account and user are classes, and must be initialized to use as arguments for creating an instance of personalization. Refer to the objects below for information on how to initialize them.

Account Object

This object contains information about the account.

Export this class using the following code:

let account = Account(
  instance: ,  // Instance for the domain
  domain: ,  // Domain name
  name: ,  // Account name
  shortname:  // Short name for the account
)

You must provide data for these variables.

Example code:

let account = Account(
  instance: "p",  // Instance for the domain
  domain: "localhost.org",  // Domain name
  name: "a-701b448c",  // Account name
  shortname: "localhost"  // Short name for the account
)

User Object

This object contains information about the user.

Create an instance of this class using the following code:

let user = User(
  monetateId: , // Monetate ID
  deviceId: , // Device ID
  customerId: // Customer ID.
)

When creating this object, you must set either the device ID or the Monetate ID with the above method calls. The recommended ID to use is the device ID.

  • monetateId: An ID generated from the Monetate server. You can generate this ID using the generateMonetateID method of the Personalization class.
  • deviceId: The ID of the user's device. The recommended ID to use.
  • customerId: The ID of the customer. This ID is optional. If you define it here, you must also pass it in calls with the other ID you use. You can later change the customer ID with the setCustomerId method.

When you create a Personalization object for the first time, there is no Monetate ID to associate with the User object. You must first initialize a User object with a device ID. After you do that, you can generate a Monetate ID for the User object by calling the generateMonetateID method. The following example code demonstrates how to do this:

final var objPersonalization = Personalization(account: Account(instance: "p", domain: "localhost.org", name: "a-701b337c", shortname: "localhost"), user: User(deviceId: "62bd2e2d-213d-463f-83bb-12c0b2530a14", customerId: "12345")) 
let monetateId =  objPersonalization.generateMonetateID()