11.0Dengage is available through CocoaPods.
To install it, simply add the following line to your Podfile:
Run pod install via terminal
Installing the iOS SDK via Swift Package Manager (SPM) automates the majority of the installation process for you. Before beginning this process, ensure that you are using Xcode 12 or greater.
Open your project and navigate to your project's settings. Select the tab named Package Dependencies and click on the add button (+) at the bottom left.
Enter the URL of our iOS SDK repository in the text field and click Add Package.
Paste URL: https://github.com/dengage-tech/dengage-ios-sdk.git
Select the latest branch. You can find the latest released branch here https://github.com/dengage-tech/dengage-ios-sdk/tags
On the next screen, select the SDK version and click Add Package.
Select the package and click finish.
The Dengage SDK is organized into 2 modules, allowing you to import only what you need:
Dengage module.DengageGeofence module in addition to the Dengage module.| Module | Description |
|---|---|
| Dengage | Core module required for analytics, in-app messaging and APNS messaging service integration. |
| DengageGeofence | Enables geofence features. |
For the initial setup, if you have been provided with URL addresses by the Dengage Support Team, you need to configure these URLs in the Info.plist file.
Refer to the API Endpoints By Datacenter section to correctly set your API endpoints.
Here’s an example configuration:
Note: Ensure the URLs match the ones provided by the Dengage Support Team and are appropriate for your data center.
start method should be called once at the beginning of your application's lifecycle to initialize the Dengage SDK. It is recommended to place it inside the application(_:didFinishLaunchingWithOptions:) method of your AppDelegate class.
Recommendation: Call it inside the
AppDelegateclass'sdidFinishLaunchingWithOptionsmethod.
| Parameter Name | Description |
|---|---|
| apiKey | The integration key generated by the CDMP Platform while defining the application. It is a hash string containing application details. |
| application | The UIApplication instance passed to the application(_:didFinishLaunchingWithOptions:) method in AppDelegate. |
| launchOptions | The launch options dictionary passed to the application(_:didFinishLaunchingWithOptions:) method in AppDelegate. |
| dengageOptions | Configuration options for the Dengage SDK. See below for details. |
The DengageOptions parameter allows you to configure various Dengage SDK settings:
| Option | Description |
|---|---|
disableOpenURL | Prevents links from opening in Safari when clicked in push notifications. |
badgeCountReset | Resets the app badge count when the push notification is clicked. |
disableRegisterForRemoteNotifications | Disables automatic push notification registration. In this case, you should be doing it in the application code. |
You can enable or disable logs comes from Dengage SDK.
The Contact Key serves as a bridge between Devices and Contacts. Devices can be categorized into two types:
To associate devices with their respective contacts, the Contact Key must be set in the SDK.
Recommended Usage:
You should call this method if you have user information. It is recommended to call this method during every app launch, as well as on login and logout pages.
You can set a unique device id of for current device. This id will be used to identify the device in the Dengage system.
In order to collect app events and use that data to create behavioral segments in Dengage you have to determine the type of events and data that needs to collect. Once you have determined that, you will need to create a “Big Data” table in Dengage. Collected events will be stored in this table. Multiple tables can be defined depending on your specific need.
Any type of event can be collected. The content and the structure of the events are completely flexible and can be changed according to unique business requirements. You will just need to define a table for events.
Once defined, all you have to do is to send the event data to these tables. Dengage SDK has only 2 functions for sending events: sendDeviceEvent and sendCustomEvent. Most of the time you will just need the sendDeviceEvent function.
For eCommerce accounts, there are predefined event tables. And you can feed these tables by using eCommerce event functions.
If the user logs in or you have user information, this means you have contact_key for that user. You can set contact_key in order to match user with the device.
If user logged in set user id. This is important for identifying your users. You can put this function call in every page. It will not send unnecessary events.
If you need to get contact key of current user from SDK use the function below:
If your Dengage account is an eCommerce account, you should use standard eCommerce events in the SDK. If you need some custom events or your account is not a standard eCommerce account, you should use custom event functions.
Dengage SDK includes standard eCommerce events:
Each event corresponds to related tables in your account.
Page view events are sent to the page_view_events table. If you've added new columns to this table, include them in the event data.
For other pages you can send anything as page_type
These events are stored in shopping_cart_events and shopping_cart_events_detail tables. The following functions are available for shopping cart events:
addToCartremoveFromCartviewCartbeginCheckoutOrder events are stored in order_events and order_events_detail tables.
Search events are stored in the search_events table.
These events are stored in wishlist_events and wishlist_events_detail tables. The available functions are:
addToWishlistremoveFromWishlistYou can send all items in the wishlist for every event, simplifying the tracking of the current wishlist items.
Use the sendDeviceEvent function to send events specific to a device. Events are sent to a big data table defined in your D·engage account, which must have a relation to the master_device table. If you set a contact_key for that device, collected events will be associated with the user.
Complete the APNS iOS Setup to configure your iOS application for push notifications.
Set up the AppDelegate class to handle push notifications. The following code snippets demonstrate how to handle push notifications in your application.
To handle push messages, you need to include the Notification Service Extension in your project. This extension is used to modify the content of remote notifications before they are displayed to the user. Place the following block inside the <extensions> tag of your Info.plist file to ensure proper integration:
Add the Dengage SDK to your Notification Service Extension target in your Podfile:
Make sure the version of the SDK matches the version in your main target.
Run pod install via terminal
Open your project and navigate to your project's settings. Select the tab named Package Dependencies and click on the add button (+) at the bottom left.
Enter the URL of our iOS SDK repository in the text field and click Add Package.
Paste URL: https://github.com/dengage-tech/dengage-ios-sdk.git
Select the latest branch. You can find the latest released branch here https://github.com/dengage-tech/dengage-ios-sdk/tags
On the next screen, select the SDK version and click Add Package. Select your Notification Service Extension target and click finish.
Modify the NotificationService.swift file to include the Dengage SDK. This file is used to handle push notifications and is automatically generated when you add the Notification Service Extension to your project. Replace the contents of the file with the following code:
Subscription is self-managed by SDK.
Definition: Subscription is a process which is triggered by sending subscription event to Dengage. It contains necessary information about application to send push notifications to clients.
The SDK automatically sends subscription events in the following scenarios:
Note: Android doesn't require to ask for push notifications explicitly. Therefore, you can only ask for push notification's permissions on iOS.
IOS uses shared UNUserNotificationCenter by itself while asking user to send notification. Dengage SDK manager uses UNUserNotificationCenter to ask permission as well.
Referrer: Apple Docs
If in your application, you want to get notification permissions explicitly, you can do by calling one of the following methods:
Retrieve the token for the current user’s subscription using this method.
If you manage your own user permission states on your application you may send user permission by using setUserPermission method.
To handle carousel push messages, you need to include the Notification Content Extension in your project. This extension is used to customize the appearance of your app’s notifications.
Change the Info.plist file of your Notification Content Extension target to include the following block:
You need add Dengage SDK to your Notification Content Extension target as described in the Notification Service Extension section.
Open NotificationViewController.swift and replace the whole file contents with the below code.
App Inbox is a screen within a mobile app that stores persistent messages. It's kind of like an email inbox, but it lives inside the app itself. App Inbox differs from other mobile channels such as push notifications or in-app messages. For both push and in-app messages, they're gone once you open them.
In other words, Dengage admin panel lets you keep selected messages on the platform and Mobile SDK may receive and display these messages when needed.
In order to save messages into App Inbox, you need to select the "Save to Inbox" option when sending messages in D·engage the admin panel by assigning an expiration date to it.
After selecting your Push content, you must activate the "Save To Inbox" option.
To use the app inbox feature, please send an email to tech@dengage.com.
Inbox messages are kept in the memory storage of the phone until the app is completely closed or for a while and Dengage SDK provides functions for getting and managing these messages.
When a push message is received with the addToInbox parameter, the message is saved during the notification building stage, allowing users to access these messages later. The following methods facilitate interaction with these messages:
Retrieve stored inbox messages with pagination:
Delete a specific inbox message:
Delete all inbox messages:
Mark a message as clicked to update its status:
Mark all inbox messages as clicked to update their status:
receiveDateproperty is used to store inbox message receive date. It keeps date as a UTC time format ("yyyy-MM-ddTHH:mm:ss.fffZ"). The applications which are using our SDKs need to convert this UTC date to the client time zone if the applications want to display the message receive date to their users.
An in-app message is a type of mobile message where the notification is displayed within the app. It is not sent at a specific time but it is shown to users when the user is using the app.
Examples include popups, yes/no prompts, banners, and more.
In order to show in-app messages, there is no permit requirement.
Created messages will be stored in Dengage backend and will be served to mobile SDKs.
If you integrated mobile SDK correctly for push messages, for using in-app features you just have to add setNavigation function to every page navigation.
If you want to use a screen name filter, you should send the screen name to setNavigation function in every page navigation.
You should pass the current activity to setNavigation function.
You can use the real time in-app functionality by using the function.
You can set custom device information that will be available in your in-app message templates using Mustache templating.
The custom device information you set will be accessible in your in-app message HTML content through the dnInAppDeviceInfo object. For example, in your in-app message template, you can use:
The In-App Inline feature allows you to seamlessly integrate inline in-app messages into your app's content, dynamically populating specific parts of your app for a better user experience.
Parameters:
inAppInlineElement An instance of InAppInlineElementView that will display the inline in-app message.propertyID The IOS selector linked to the in-app inline campaign created in the Dengage panel.customParams (optional) A Dictionary of custom parameters used for filtering inline messages.screenName (optional) Specifies the screen where the inline in-app message will be displayed.hideIfNotFound (optional, default: false) If set to true, the InAppInlineElementView will be hidden if no inline message is found.The App Stories feature allows you to display story-like content within your app.
The showAppStory method accepts a completion handler that yields an optional StoriesListView reference – this callback returns nil when no App Stories match the specified parameters.
Parameters:
screenName (optional) Specifies the screen where the app stories should be displayed.storyPropertyID The story property ID associated with the app stories campaign created in the Dengage panel.customParams (optional) A Dictionary of custom parameters used for filtering stories.storyCompletion A completion handler that yields an optional StoriesListView reference.DengageGeofence is available through CocoaPods.
To install it, simply add the following line to your Podfile:
Run pod install via terminal
Ensure the
DengageGeofenceversion matches theDengageversion.
To install the SDK via Swift Package Manager (SPM), follow the same steps as the Dengage SDK installation.
Ensure the
DengageGeofenceversion matches theDengageversion.
To enable location services you should add the following keys to your Info.plist file:
After initializing the core SDK with Dengage.init, you can enable geofence by calling the DengageGeofence.startGeofence method in your AppDelegate class.
To request location permissions at runtime, use the DengageGeofence.requestLocationPermissions method.
Geofence usage can have significant impacts on your application's performance and battery consumption. Here are important considerations:
When a geofence is triggered while the app is not running (terminated state), iOS launches the app in the background and calls the application(_:didFinishLaunchingWithOptions:) method. This has important implications:
didFinishLaunchingWithOptions will execute when a geofence triggers, even if the user hasn't explicitly opened the app. Ensure your initialization code handles this scenario gracefully.didFinishLaunchingWithOptions. These will delay geofence event processing and may cause the system to terminate your app.DengageGeofence SDK uses iOS's native region monitoring capabilities with the following characteristics:
CLLocationManager's region monitoring (not continuous GPS tracking), which is battery-efficient as iOS handles geofence detection at the system level.Minimize Background Work: When the app is launched due to a geofence trigger, minimize the work performed:
Test Background Scenarios: Thoroughly test your app's behavior when launched from a terminated state due to geofence triggers. Use Xcode's location simulation features to test various scenarios.
User Communication: Inform users about the benefits of location permissions and how geofencing enhances their experience. Users are more likely to grant "Always" location permission if they understand the value.
Note: If your app doesn't require geofence functionality, avoid including the
DengageGeofencemodule to prevent unnecessary location permission requests.