Initializing the Swift SDK
Start using the SDK by instantiating the DYSdk object.
The initialize
method sets up the initial global configuration for the SDK, which is used across different functions.
The following fields must be set during the initialization step, and can't be modified afterwards:
- apiKey: To use the Dynamic Yield SDK, you need an API key generated in Experience OS. To create one, follow this guide. A server-side API key is recommended for SDK use.
- dataCenter: Your section is in one of our two data centers: US or EU.
Other parameters can be adjusted after the initialization using setters.
Call the initialize
method once at the beginning of your SDK setup.
Parameters
The following table lists the parameters the initialize method accepts:
Parameter | Type | Description |
---|---|---|
apiKey Required | String | Unique API Key for authentication generated in Experience OS. |
dataCenter Required | DataCenter | The Dynamic Yield data center to connect to (DataCenter.US or DataCenter.EU). |
deviceType | DeviceType | The type of device being used. Valid values are: SMARTPHONE , TABLET , KIOSK , ODMB * KIOSK and ODMB are relevant for Restaurants only. |
channel | Channel | The digital channel through which the user is interacting. When used, the default value is Channel.APP . Other possible values are: KIOSK , DRIVE_THRU . |
ip | String | The device IP address for geolocation-based targeting and audience building. |
locale | String | Used to configure the locale that will be used for all DY experiences. Learn more about using localization and country codes for locale. |
isImplicitPageview | Boolean | Determine whether to automatically report a new pageview when calling Choose Variations. This is set to false by default. |
isImplicitImpressionMode | Boolean | Determine whether to automatically report an impression for all variations returned by the Choose call. This is set to true by default. |
customUrl | String | Relevant when using a proxy server. In such cases, the dataCenter parameter is ignored. |
sharedDevice For Restaurants only | Boolean | Indicates whether the device running the application is shared among multiple users. This parameter defaults to false. Consult your technical account manager before changing this value. |
deviceId For Restaurants only | String | A unique identifier for the device. |
Example
DYSdk.initialize(apiKey: "myApiKey",
dataCenter: .eu,
deviceType: .smartphone,
sharedDevice: true,
deviceId: "myId",
channel: .app,
ip: "123.45.67.890",
locale: "en",
isImplicitPageview: true,
isImplicitImpressionMode: true)
DYSdk setters
Method name | Parameter |
---|---|
setDeviceType | DeviceType |
setChannel | Channel |
setIp | String |
setLocale | String |
setIsImplicitPageview | Boolean |
setIsImplicitImpressionMode | Boolean |
setLogLevel | LogLevel |
DYSdk getters
Method name | Return Value |
---|---|
getLogLevel | LogLevel? |
getDyId (see note) | String? |
getSessionId (see note) | String? |
Note: Return values might be null or an empty string if not assigned yet (before the first call to the Choose Variations function).
Updated 5 days ago