MoEngage integration for analytics-swift.
In the Xcode File
menu, click Add Packages
. You'll see a dialog where you can search for Swift packages. In the search field, enter the URL to this repo.
-
Get
MoEngage-Segment-Swift
xcframework(s) from releases. Use this version for checking dependencies inPackage.swift
. -
Get MoEngage SDK XCFrameworks: a. Get supported MoEngage SDK version range from
Package.swift
. a. Get XCFrameworks forMoEngageSecurity
,MoEngageCore
,MoEngageObjCUtils
,MoEngageAnalytics
,MoEngageMessaging
andMoEngageSDK
from URLs present inpackage.json
for supported version. -
Get Segment XCFrameworks: a. Get supported Segment SDK version range from
Package.swift
. a. Get XCFrameworks for for supported version from Segment releases. -
Add all the XCFrameworks to
Frameworks, Libraries, and Embedded Content
section for the app target.
Now head to the App Delegate file, and setup the Segment SDK by
- Importing
Segment
,Segment_MoEngage
andMoEngageSDK
. - Initialize
MoEngageSDKConfig
object and callinitializeDefaultInstance
method ofMoEngageInitializer
. - Initialize
MoEngageDestination
as shown below:
Under your Analytics-Swift library setup, add the MoEngage plugin using analytics.add(plugin: ...)
method. Now all your events will be tracked in MoEngage dashboard.
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
.flushAt(3)
.trackApplicationLifecycleEvents(true))
analytics.add(plugin: MoEngageDestination())
import Segment_MoEngage
import MoEngageSDK
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
let sdkConfig = MoEngageSDKConfig(withAppID: "YOUR APP ID")
MoEngageInitializer.shared.initializeDefaultInstance(sdkConfig: sdkConfig)
// Add your configuration key from Segment
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
.flushAt(3)
.trackApplicationLifecycleEvents(true))
// Add Moengage Destination Plugin to send data from Segment to MoEngage
analytics.add(plugin: MoEngageDestination())
...
}
To setup MoEngage do the following:
- First get your key from MoEngage dashboard. (Dashboard -> Settings -> General -> General Settings -> AppID)
- Go to Segment dashboard, go to Integrations and select MoEngage.
- Enable MoEngage Integration.
- Go to MoEngage Settings and enter the MoEngage AppID, obtained in Step1.
- Save the changes.
These new settings will take up to an hour to propogate to all of your existing users. For new users it’ll be instanteneous! Segment-MoEngage Integration is a bundled integration, requires client side integration.
User attributes are specific traits of a user, like email, username, mobile, gender etc. identify lets you tie a user to their actions and record traits about them. It includes a unique User ID and any optional traits you know about them.
Analytics.main.identify(userId: "a user's id", traits: ["email": "a user's email address"])
For more info refer to this link.
Event tracking is used to track user behaviour in an app. track lets you record the actions your users perform. Every action triggers i.e,“event”, which can also have associated attributes.
Analytics.main.track(name: "Item Purchased", properties: ["item": "Sword of Heracles"])
That's all you need for tracking data. For more info refer this link.
The reset method clears the SDK’s internal stores for the current user. This is useful for apps where users can log in and out with different identities over time.
Analytics.main.reset()
For more info refer to this link.
Since you might integrate us when your app is already on the App Store, we would need to know whether your app update would be an actual UPDATE or an INSTALL. To differentiate between those, use one of the method below:
//For new Install call following
MoEngageSDKAnalytics.sharedInstance.appStatus(.install);
//For an app update call following
MoEngageSDKAnalytics.sharedInstance.appStatus(.update);
For more info on this refer following link.
Along with tracking your user's activities, MoEngage iOS SDK also provides additional features which can be used for more effective user engagement:
Push Notifications are a great way to keep your users engaged and informed about your app. You have following options while implementing push notifications in your app:
1.Follow the directions to register for push using Segment SDK in this link.
2.In your application’s application:didReceiveRemoteNotification: method, add the following:
Analytics.main.receivedRemoteNotification(userInfo: userInfo)
3.If you integrated the application:didReceiveRemoteNotification:fetchCompletionHandler: in your app, add the following to that method:
Analytics.main.receivedRemoteNotification(userInfo: userInfo)
Follow this link to implement Push Notification in your mobile app using MoEngage SDK: Push Notifications
In-App Messaging are custom views which you can send to a segment of users to show custom messages or give new offers or take to some specific pages. Follow the link to know more about inApp Messaging and how to implement it in your application: InApp NATIV
For more info on using Segment for iOS refer to Developer Docs provided by Segment.
See SDK Change Log for information on every released version.
For any issues you face with the SDK and for any help with the integration contact us at [email protected]
.