MBAudienceSwift is a plugin libary for MBurger, that lets you track user data and behavior inside your and to target messages only to specific users or groups of users. This plugin is often used with the MBMessagesSwift plugin to being able to send push and messages only to targeted users.
With Xcode 11 you can start using Swift Package Manager to add MBAudienceSwift to your project. Follow those simple steps:
https://github.com/Mumble-SRL/MBAudienceSwift.git
in the "Choose Package Repository" dialog and press Next.MBAudienceSwift
library and add it to your app target.CocoaPods is a dependency manager for iOS, which automates and simplifies the process of using 3rd-party libraries in your projects. You can install CocoaPods with the following command:
$ gem install cocoapods
To integrate the MBurgerSwift into your Xcode project using CocoaPods, specify it in your Podfile:
platform :ios, '12.0'
target 'TargetName' do
pod 'MBAudienceSwift'
end
If you use Swift rememember to add use_frameworks!
before the pod declaration.
Then, run the following command:
$ pod install
CocoaPods is the preferred methot to install the library.
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate MBudienceSwift into your Xcode project using Carthage, specify it in your Cartfile:
github "Mumble-SRL/MBAudienceSwift"
To install the library manually drag and drop the folder MBAudienceSwift
to your project structure in XCode.
Note that MBAudienceSwift
has MBurgerSwift (1.0.5)
and MPushSwift (0.2.12)
as dependencies, so you have to install also those libraries.
To initialize the SDK you have to add MBAudience
to the array of plugins of MBurger
.
import MBurgerSwift
import MBMessagesSwift
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
MBManager.shared.apiToken = "YOUR_API_TOKEN"
MBManager.shared.plugins = [MBAudience()]
return true
}
You can set a delegate when initializing the MBAudience
plugin, the delegate will be called when audience data are sent successfully to the sever or if the sync fails
let audiencePlugin = MBAudience(delegate: [the delegate])
Below are described all the data that are tracked by the MBAudience SDK and that you will be able to use from the MBurger dashboard. Most of the data are tracked automatically, for a couples a little setup by the app is neccessary.
Locale.preferredLanguages.first
.didEnterBackgroundNotification
) .and it's resumed when the app re-become active (using willEnterForegroundNotification
).UNUserNotificationCenter.current().getNotificationSettings
.CLLocationManager.authorizationStatus()
is authorizedAlways
or authorizedWhenInUse
.You can set tags to assign to a user/device (e.g. if user has done an action set a tag), so you can target those users later:
To set a tag:
MBAudience.setTag("TAG", value: "VALUE")
To remove it:
MBAudience.removeTag("TAG")
You can set a custom id in order to track/target users with id coming from different platforms.
To set a custom id:
MBAudience.setCustomId("CUSTOM_ID")
To remove it:
MBAudience.removeCustomId()
To retrieve the current saved id:
MBAudience.getCustomId()
This is the id of the user currently logged in MBurger using MBAuth. At the moment the mobile user id is not sent automatically when a user log in/log out with MBAuth. It will be implemented in the future but at the moment you have to set and remove it manually when the user completes the login flow and when he logs out.
To set the mobile user id:
MBAudience.setMobileUserId(MOBILE_USER_ID)
To remove it, if the user logs out:
MBAudience.removeMobileUserId()
To get the currently saved mobile user id:
MBAudience.getMobileUserId()
MBAudience let you track and target user based on their location, the framework uses the method startMonitoringSignificantLocationChanges of the CoreLocation manager with an accuracy of kCLLocationAccuracyHundredMeters
. To start monitoring for location changes call, it will continue monitoring until the stop method is called:
MBAudience.startLocationUpdates()
To stop monitoring location changes you have to call:
MBAudience.stopLocationUpdates()
link |
Stars: 0 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics