- Xcode 9.0+
- iOS 9.0+
The UserReport iOS SDK can be installed in various ways.
CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.
-
Add the project to your Podfile.
pod 'UserReport'
-
Run
pod install
and open the.xcworkspace
file to launch Xcode. -
Import the UserReport framework.
import UserReport
Swift Package Manager is a tool for managing the distribution of Swift code
- Go to File > Swift Packages > Add Package Dependency...
- Put UserReport SDK Github url
- Click
Branch: ‘master’
- Choose appropriate target
To install it manually drag the UserReport project into your app project in Xcode or add it as a git submodule. In your project folder enter:
$ git submodule add [email protected]:AudienceProject/userreport-ios-sdk.git
Update your Info.plist
with message that will inform the user why app is requesting permission to use data for tracking:
<plist ...>
<dict ...>
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
</dict>
</plist>
Configure the UserReport iOS SDK using your PUBLISHER_ID
and your MEDIA_ID
.
Your PUBLISHER_ID
and MEDIA_ID
can be found on the Media Setting page in UserReport.
// Configure
UserReport.configure(sakId: "PUBLISHER_ID", mediaId: "MEDIA_ID")
If you want to automatically measure all screen views, your application's ViewController
s should inherit from the UserReportViewController
class.
Example of automatic tracking:
class ViewController: UserReportViewController {
...
}
There are two types of tracking:
- Screen view tracking (
UserReport.trackScreenView()
) - Section view tracking (
UserReport.trackSectionScreenView()
)
If a media (website) has one single topic, it can be tracked using UserReport.trackScreenView()
.
If a website has different sections, for instance Health, World news and Local news, then it should be tracked using both UserReport.trackScreenView()
and UserReport.trackSectionScreenView(sectionId)
. The sectionId
for a particular section can be found on the Media Setting page in UserReport.
Example of manual screen tracking:
class ViewController: UIViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Tracking screen view
UserReport.trackScreenView()
}
}
Example of manual section tracking:
class ViewController: UIViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Tracking section view (use both functions)
UserReport.trackScreenView()
UserReport.trackSectionScreenView(sectionId)
}
}
If you use the UserReport.trackSectionScreenView
and/or UserReport.trackScreenView()
methods, then automatic tracking should be disabled. As you can see in the manual tracking example, the ViewController
does not inherit from UserReportViewController
.
Configure the UserReport iOS SDK using your SAK_ID
, your MEDIA_ID
and information about the user.
Your SAK_ID
and MEDIA_ID
can be found on the Media Setting page in UserReport.
// Create user object (optional)
let user = UserReportUser()
user.email = "[email protected]"
// You can also specify a email hash
user.emailMd5 = "MD5_EMAIL_HASH"
user.emailSha1 = "SHA1_EMAIL_HASH"
user.emailSha256 = "SHA256_EMAIL_HASH"
// Provide additional social network information
user.facebookId = "FACEBOOK_ID"
//It is possible to override the default rules for when a survey will appear.
//However, the settings parameter is optional.
let settings = UserReportSettings()
settings.sessionScreensView = 5
settings.inviteAfterNSecondsInApp = 20
// Configure
UserReport.configure(sakId: "YOUR_SAK_ID", mediaId: "YOUR_MEDIA_ID", user: user, settings: settings)
The survey can appear in two ways:
.alert
- show survey like an alert view (Default).fullScreen
- show survey in full-screen mode, like the modal view controller
To change the display mode, please specify following:
UserReport.setDisplayMode(.fullscreen)
To update the default rules for appear the survey use follow:
Though, it is recommended to pass UserReportSettings
to configure method instead, use this method only when you want to change rules for already launched app
let settings = UserReportSettings()
settings.sessionScreensView = 5
settings.inviteAfterNSecondsInApp = 20
UserReport.updateSettings(settings)
For the survey not to appear on important screens, you can use a variable mute
.
UserReport.mute = true
Do not forget to restore value back to
false
.
When changing user data, you should also send the updated data to the UserReport iOS SDK.
let user = UserReportUser()
user.email = "[email protected]"
UserReport.updateUser(user)
UserReport SDK stores the data on the count of screens viewed and the time the application is used. If necessary, you can get this data from a variable session
. The session contains the following values:
screenView
- number of screens viewed in the current sessiontotalScreenView
- number of screens viewed in all sessionsessionSeconds
- number of seconds spent in the application for current sessiontotalSecondsInApp
- number of seconds spent in the application for all timelocalQuarantineDate
- date until the survey will not appear againsettings
- current settings for the survey appearance
// Session information about the running time of the application and screen views
let session = UserReport.session
// Get current settings for appear survey
let currentSetting = session?.settings
If you decide to show the survey yourself, then you can use the following method:
UserReport.tryInvite()
If anonymous tracking is enabled: all requests will be fired to the do-not-track domain and IDFA will never be sent. To enable anonymous mode you can use following method:
UserReport.setAnonymousTracking(true)
The SDK relies on IDFAs, so make sure to mark the appropriate checkboxes when publishing your app.
UserReport iOS SDK is released under the Apache License 2.0. See LICENSE for details.