Gamify Loyalty Widget SDK
Overview
The Gamify Widget SDK lets your app embed the Gamify loyalty widget so your end users can view their missions and prizes—opened from a single entry point in your app, such as a "Rewards" button.
It is a self-contained module available across all four Optimove SDKs: Android, iOS, React Native, and Web.
- Mobile (Android, iOS, React Native) renders the widget in a native modal surface backed by a
WebView. - Web renders the widget as a full-screen iframe overlay, or embedded inside a host element you name.
The Gamify Widget SDK is part of the core Optimove SDK, which must be initialized first. The widget URL is delivered in your Optimove tenant configuration, so you don't need to provide it.
Before You Begin
Supported SDK Versions
The Gamify Widget SDK is available from these minimum versions:
| Platform | Minimum version | Notes |
|---|---|---|
| Android | optimove-android 7.20.0+ | Adds openWidget(activity, params) and federated authentication support.GamifyWidgetSDK ships inside the optimove-android artifact—no separate dependency. |
| iOS | OptimoveSDK 6.13.0+ | Adds openWidget(from:params:) and federated authentication support.GamifyWidgetSDK is part of OptimoveSDK. |
| React Native | @optimove-inc/react-native 3.2.0+ | First release with gamifyWidgetOpen. |
| Web | Web SDK 1.0.0.47+ | Adds openWidget({...}) and federated authentication support. |
Upgrading from an earlier Android SDK version
GamifyWidgetSDK.initialize(...)andGamifyWidgetSDK.getInstance().open(...)still work but are deprecated, and log an error on each call. UseGamifyWidgetSDK.getInstance().openWidget(activity, params)instead; the widget URL now comes from your tenant configuration, andopenAdactCampaignno longer needsinitialize. Instead of passing atoken, use federated authentication for authenticated widget sessions.
Upgrading from an earlier iOS SDK version
GamifyWidgetSDK.initialize(widgetUrl:)andGamifyWidgetSDK.open(from:userId:)were removed. UseGamifyWidgetSDK.openWidget(from:params:)instead; the widget URL now comes from your tenant configuration. If you need authenticated widget sessions, use federated authentication.
Upgrading from an earlier Web SDK version
openWidget(widgetUrl, elementId?, userId?)still works but is deprecated. UseopenWidget({ userId, elementId, brand })instead. Thetokenargument was removed. If you need authenticated widget sessions, use federated authentication.
The userId Parameter
userId is optional in the call, but the widget needs a user. If you don't pass one, the SDK uses the user identified with setUserId (optimoveSDK.API.setUserId(...) on Web, Optimove.setUserId(_:) on iOS, Optimove.getInstance().setUserId(...) on Android). If there is neither, the widget does not open.
The userId you pass to the open call is your raw Optimove Customer ID—the same identifier you already use elsewhere. Internally the Gamify system also calls this value the player id, and the widget/public API refers to it as playerId. These are three names for one and the same string:
userId(SDK open call) =playerId(widget / public API) = your raw Optimove Customer ID
The player profile response also returns an internal UUID field
id, marked "distinct fromplayerId." That is Gamify's internal row key—never what you pass to the widget. Theidyou pass toopenis always the raw Customer ID.
Federated Authentication
The loyalty widget supports Optimove federated authentication. When it is enabled, every widget session is authenticated with a JWT from your own token provider. No widget-specific setup is needed.
For full setup details, see the Federated Authentication in the Optimove SDK guide.
Integrate on Android
Requires optimove-android 7.20.0+. GamifyWidgetSDK is bundled inside the optimove-android artifact, so there is no separate dependency to add.
openWidget takes the current activity and an optional OpenLoyaltyWidgetParams:
| Field | Type | Description |
|---|---|---|
userId | String? | Optional. Defaults to the user identified with Optimove.getInstance().setUserId(...). |
brand | String? | Optional. Opens the widget for a specific brand. |
import com.optimove.android.gamifywidgetsdk.GamifyWidgetSDK
import com.optimove.android.gamifywidgetsdk.OpenLoyaltyWidgetParams
// Open the widget for the identified user
GamifyWidgetSDK.getInstance().openWidget(activity)
// or, for a specific user and brand
GamifyWidgetSDK.getInstance().openWidget(activity, OpenLoyaltyWidgetParams("customer-123", "brand-a"))
// Close it programmatically
GamifyWidgetSDK.getInstance().closeWidget()
Deprecated Methods
The previous methods still work, but they are deprecated, log an error on each call, and will be removed in a future version:
GamifyWidgetSDK.initialize(widgetUrl, adactUrl)
GamifyWidgetSDK.getInstance().open(activity, userId)The URL you pass to
initializeis opened as given. AnadactUrlpassed toinitializetakes precedence over the one in your tenant configuration.
Integrate on iOS
Requires OptimoveSDK 6.7.0+. GamifyWidgetSDK is part of OptimoveSDK.
openWidget takes the presenting view controller and an optional OpenLoyaltyWidgetParams:
| Field | Type | Description |
|---|---|---|
userId | String? | Optional. Defaults to the user identified with Optimove.setUserId(_:). |
brand | String? | Optional. Opens the widget for a specific brand. |
import OptimoveSDK
// Open the widget for the identified user
GamifyWidgetSDK.openWidget(from: self)
// or, for a specific user and brand
GamifyWidgetSDK.openWidget(from: self, params: OpenLoyaltyWidgetParams(userId: "customer-123", brand: "brand-a"))
// Close it programmatically
GamifyWidgetSDK.closeWidget()
iOS and Android Edge Cases
- No user or widget not enabled: if no user is available, the tenant configuration has not loaded yet, or the loyalty widget is not enabled for your tenant,
openWidgetlogs an error naming what is missing and does nothing. It does not crash. - Already open: if the widget is already open, a second
openWidgetcall is ignored. - Links: links that leave the widget's site open in the system browser.
Integrate on React Native
Requires @optimove-inc/react-native 3.2.0+. There is no separate class—gamifyWidgetOpen is a static method on the default-imported Optimove. You pass the widget URL directly to the open call.
import Optimove from '@optimove-inc/react-native';
// Open the widget. userId is optional.
Optimove.gamifyWidgetOpen("https://opti-ls-widget-<region>.optimove.net/<tenantId>/customerId>", userId);Integrate on Web
Requires Web SDK 1.0.0.38+. There is no import—the module is loaded at runtime and accessed via optimoveSDK.API.gamify on the global object. openWidget takes one optional object:
| Field | Type | Description |
|---|---|---|
userId | string | Optional. Defaults to the user identified with optimoveSDK.API.setUserId(...). |
elementId | string | Optional. Omit it for a fullscreen overlay, or pass an element id to embed the widget inside that element. |
brand | string | Optional. Opens the widget for a specific brand. |
Fullscreen Overlay
Omit elementId (pass undefined) to render the widget as a fullscreen iframe overlay:
optimoveSDK.API.gamify.openWidget();
// or, for a specific user
optimoveSDK.API.gamify.openWidget({ userId: 'customer-123' });
Embedded in a Host Element
Pass the id of an existing element to render the widget inside it:
optimoveSDK.API.gamify.openWidget({ elementId: 'my-container-div' });
Deprecated Signature
The previous form still works, but it is deprecated and will be removed in a future version:
optimoveSDK.API.gamify.openWidget(widgetUrl, elementId, userId);The URL you pass is opened as given, and federated authentication still applies. The URL must use
https:. OtherwiseopenWidgetlogs a console error and does nothing.
Closing the Widget
closeWidget() closes the widget. It is also wired to the overlay's ✕ button and to the widget's internal CLOSE message.
optimoveSDK.API.gamify.closeWidget();Web Constraints and Edge Cases
- Missing host element: if
elementIddoes not match an existing element,openWidgetlogs a console error and does nothing. Make sure the element is in the DOM before you call it. - Already open: if a widget is already open, a second
openWidgetcall is ignored and a console warning is logged. - No user or widget not enabled: if no user is available, or the loyalty widget is not enabled for your tenant,
openWidgetlogs a console error and does nothing.
What to Expect When the Widget Opens
On mobile (Android, iOS, React Native), the widget opens in a native modal surface backed by a WebView. On iOS you can close the widget with GamifyWidgetSDK.closeWidget(), and on Android with GamifyWidgetSDK.getInstance().closeWidget(). Otherwise it is dismissed by the user (swipe-down on the iOS sheet, the Back button on Android, or the modal's own ✕), or when the widget itself signals completion and tears down the surface.
On web, the widget opens as a fullscreen overlay (dismissed via closeWidget(), the overlay ✕, or the widget's internal close), or rendered inside the host element you named.
On every platform, the open and close calls return void. There are no public success or error callbacks or events for the widget itself. The one exception is on Web with federated authentication: token errors are reported to the onAuthError callback you passed to configureAuth. The widget manages its own lifecycle internally.
Quick Reference
| Platform | Min version | Entry point | Programmatic close |
|---|---|---|---|
| Android | optimove-android 7.20.0+ | GamifyWidgetSDK.getInstance().openWidget(activity, params?) with OpenLoyaltyWidgetParams(userId?, brand?) | Yes — `GamifyWidgetSDK.getInstance().closeWidget()` |
| iOS | OptimoveSDK 6.13.0+ | GamifyWidgetSDK.openWidget(from:params:) with OpenLoyaltyWidgetParams(userId?, brand?) | Yes — `GamifyWidgetSDK.closeWidget()` |
| React Native | @optimove-inc/react-native 3.2.0+ | Optimove.gamifyWidgetOpen(widgetUrl, userId?) | No (user-dismissed) |
| Web | Web SDK 1.0.0.47+ | optimoveSDK.API.gamify.openWidget({ userId?, elementId?, brand? }) | Yes — closeWidget() |
Updated 20 days ago
