This guide will walk you through how to install UserReport survey tool on your native iOS app: please notice that it is a technical guide and therefore it is targeted to developers.
Before proceeding with this guide, you need to configure as โ iOS appโ your media in UserReport interface. You can do this by going to the media settings and adding a new media. When asked, on which media you want to run UserReport please select iOS app.
Once this is done, and you proceed setting up your media, you will find the two SDK initializations parameters that will be needed to configure UserReport in-app code: the SAK_ID and the MEDIA_ID.
Please notice that this guide is for native iOS application written in Objective-C or Swift.
Unlike web-environment, the in-app environment does not allow to deploy tags that will allow rendering survey invitation. Therefore, some code modification is required to invite users to survey.
Implement
This instruction covers the implementation of UserReport to your application. UserReport SDK targets iOS 9.0+ and requires Xcode 9.0+. UserReport iOS SDK can be installed in various ways, let's go through them.
Cocoa Pods
Add the project to your Podfile.
use_frameworks!
pod 'UserReport'Run
pod install
and open the.xcworkspace
file to launch Xcode.Import the UserReport framework.
import UserReport
Manually
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
Usage
Configure
Configure UserReport iOS SDK via SAK_ID
, MEDIA_ID
(You can find these values on media setting page) and information about user, if your application supports authentication.
Providing user login information allows respecting user's choice to not take part in a survey and anonymously track users demographic data across different apps. If an application does not support authentication, IDFA will be used.
// Create user object
let user = User()
user.email = "[email protected]" // UserReport SDK will hash email itself, raw e-mail will not be sent.
// 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"
// Configure
UserReport.configure(sakId: "YOUR_SAK_ID", mediaId: "YOU_MEDIA_ID", user: user)
Screen Tracking
Screen tracking important part of UserReport - invitations are shown based on a number of screen-views and also Screen-views are measured for Kits. Unlike web where pageview is clearly defined, screen-view should be tracked separately in native apps. There are two possibilities in SDK - choose the one that works better for your app.
1. Manually measure screen view
To manually measure the screen view, use the method trackScreen()
.
class ViewController: UIViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Tracking screen view
UserReport.shared?.trackScreen()
}
}
2. Automatically measure the screen view
If you want to automatically measure views as screens using the UserReportViewController
class.
class ViewController: UserReportViewController {
...
}
Display Mode
You can choose how you want the survey to appear in your app: there are two ways you can choose from:
.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 the following:
UserReport.shared?.displayMode = .fullscreen
Change Settings
To update the default rules regarding how the survey appears use follow:
let settings = Settings()
settings.sessionScreensView = 5
settings.inviteAfterNSecondsInApp = 20
UserReport.shared?.updateSettings(settings)
Mute
In order for the survey not to be appear on important screens, you can use a variable mute
. Once you have done this, please don't forget to go back to false
.
UserReport.shared?.mute = true
Update user info
When changing user data, you should also send the updated data to the UserRecord iOS SDK.
let user = User()
user.email = "[email protected]"
UserReport.shared?.updateUser(user)
Session info
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 screen viewed in current sessiontotalScreenView
- number of screen viewed in all sessionsessionSeconds
- number of seconds spent in the application for current sessiontotalSecondsInApp
- number of seconds spent in the application for all timelocalQuarantineDays
- number of days through which the survey will be appear againsettings
- current settings for appear the survey
// Session information about the running time of the application and screen views
let session = UserReport.shared?.session
// Get current settings for appear survey
let currentSetting = session?.settings
Show survey manually
If you decide to show the survey yourself, then you can use the following method:
UserReport.shared?.tryInvite()