Initializing the Kotlin 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.
  • context: The application context object.

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:

Kotlin ParameterTypeDescription
apiKey
Required
StringUnique API Key for authentication generated in Experience OS.
dataCenter
Required
DataCenterThe Dynamic Yield data center to connect to (DataCenter.US or DataCenter.EU).
context
Required
android.content.ContextThe application context object.
deviceTypeDeviceTypeThe type of device being used. Valid values are: SMARTPHONE, TABLET, KIOSK, ODMB
* KIOSK and ODMB are relevant for Restaurants only.
channelChannelThe digital channel through which the user is interacting. When used, the default value is Channel.APP. Other possible values are: KIOSK, DRIVE_THRU.
ipStringThe device IP address for geolocation-based targeting and audience building.
localeStringUsed to configure the locale that will be used for all DY experiences. Learn more about using localization and country codes for locale.
isImplicitPageviewBooleanDetermine whether to automatically report a new pageview when calling Choose Variations. This is set to false by default.
isImplicitImpressionModeBooleanDetermine whether to automatically report an impression for all variations returned by the Choose call. This is set to true by default.
customUrlStringRelevant when using a proxy server. In such cases, the dataCenter parameter is ignored.
sharedDevice
For Restaurants only
BooleanIndicates 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
StringA unique identifier for the device.

Example

DYSdk.getInstance()
    .initialize(
        apiKey = "your-api-key",
        dataCenter = DataCenter.US,
        context = applicationContext,
        deviceId = "example-deviceId",
        channel = Channel.APP,
        ip = "1.2.3.4",
        locale = "en",
        isImplicitPageview = true,
        isImplicitImpressionMode = false,
)

DYSdk setters

Method nameParameter
setDeviceTypeDeviceType
setChannelChannel
setIpString
setLocaleString
setIsImplicitPageviewBoolean
setIsImplicitImpressionModeBoolean
setLogLevelLogLevel

DYSdk getters

Method nameReturn Value
getLogLevelLogLevel?
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).