Usabilla for Apps allows you to collect feedback from your users with great ease and flexibility.
In Usabilla SDK Version 6.4 there are two new features in addition to screenshot
- ability to capture image using camera
- ability to draw over image using drawing tool Note :
- For camera, iPad supports all orientations and iPhone supports portrait mode only.
- iPhone with landscape only mode doesn't support this features but there is an ability to capture image using image library)
- Usabilla for Apps - iOS SDK
- - UI Customisations
- Requirements
- Installation
- Initialization
- Campaigns
- Passive feedback
- Masking Private Identifiable Information
- Custom variables
- App Store rating
- Programmatically remove a Form or a Campaign
- Force specific interface orientation
- UI Customisations
- Localization
- Permissions
- Integration with Obj-C applications
- Custom variables
- App Store rating
- Force specific interface orientation
- UI Customisations
- iOS 9.0+
- Xcode 10+
- Swift 4.0+
You can install the Usabilla SDK using Cocoapods, Carthage or manually.
This release is build with Xcode 11.3.1 and with Module Format Stability (as of 6.4.3). It should compile and run with any version of Xcode 11+ Previous versions are available at our git-repository. For Carthage please check the Carthage section
The Usabilla SDK is available on CocoaPods. You can install CocoaPods the following way:
$ gem install cocoapods
To use the SDK in your project, specify it in your Podfile
:
use_frameworks!
target 'YourProjectTarget' do
pod 'Usabilla', '~> 6.4.7'
End
Then, run the following command:
$ pod install
The Usabilla SDK is also available through Carthage.
Follow these instructions to add carthage to your project.
And add this line to your Cartfile
:
binary "https://raw.githubusercontent.com/usabilla/usabilla-u4a-ios-swift-sdk/master/Usabilla.json"
The release in master is build for Xcode 11.3.1.
For other Xcode version, use:
binary "https://raw.githubusercontent.com/usabilla/usabilla-u4a-ios-swift-sdk/Xcode-11.4.1/Usabilla.json"
replace Xcode-11.4.1 with the required version eg. Xcode-10
You can download the latest version of the repository and add Usabilla.framework to your app’s embedded frameworks.
In doing so, you might encounter a problem while submitting your app to the App Store. This is due to a bug in the App Store itself.
You can solve it by creating a new Run Script Phase, after the Embed Frameworks phase, in your app’s target’s Build Phases, and copying the script available here.
We recommend initializing the SDK in the AppDelegate. However this is not mandatory, and the initialization can be performed elsewhere without any problem.
Import Usabilla SDK inside your AppDelegate.
import Usabilla
Add the following line to the didFinishLaunchingWithOptions:
Usabilla.initialize(appID: "appID")
You can also run a callback after the SDK is finished initializing by calling:
Usabilla.initialize(appID: "appID") {
// Your callback code here
}
The initialize method will take care of:
- Submitting any pending feedback items.
- Fetching and updating all campaigns associated with the app ID.
- Initializing a few background processes of the SDK.
⚠️ Failure to call this method will prevent the SDK from running. No functionalities at all will be available.
In order to have more insights from the SDK while developing, you can enable logging with:
Usabilla.debugEnabled = true
This property is by default set to false
.
Version 4 of the Usabilla for Apps SDK introduces the new campaigns feature. This guide describes the Campaigns feature and all the steps necessary to work with it.
In the Usabilla for Apps Platform, a campaign is defined as a proactive survey targeted to a specific set of users.
Being able to run campaigns in your mobile app is great because it allows you to collect more specific insights from your targeted users. What is even better is that creating new and managing existing campaigns can be done without the need for a new release of your app. Everything can be managed from the Usabilla web interface.
You can run as many campaigns as you like and target them to be triggered when a specific set of targeting options are met. The configuration of how a campaign is displayed to the user will be familiar to existing Usabilla customers. You can configure it to suit your needs just like you are used to from the Passive feedback forms.
The most important aspect of running a mobile campaign is 'Events'. Events are custom triggers that are configured in the SDK. When a pre-defined event occurs, it will allow you to trigger a campaign. A good example of an event is a successful purchase by a user in your app.
The app Id is an identifier used to associate campaigns to a mobile app. By loading the SDK with a specific app Id, it will fetch all the campaigns connected to the given app Id.
It is possible to target a campaign to more than one app (e.g. iOS Production App, iOS Beta App) by associating it with multiple App Ids.
Campaigns are triggered by events. Events are used to communicate with the SDK when something happens in your app. Consequently, the SDK will react to an event depending on the configuration of the Usabilla web interface. To send an event to the SDK, use :
Usabilla.sendEvent(event: String)
There are multiple options which allow you to define more specific targeting rules of a campaign:
- You can set the number of times an event has to occur (e.g. 3 times).
- Specify the percentage of users for whom the campaign should be triggered (e.g. 10%).
- Define whether you would like to target a specific device language.
You can also segment your user base using custom variables. Custom variables can be used to specify some traits of the user and target the campaign only to a specific subset.
For more on how to use custom variables, read Custom Variables
Note: A campaign will never be triggered for the same user more than once.
The Usabilla SDK allows you to make sure no campaigns trigger at an inappropriate moment. For example, when the user of your app is in the middle of a delicate process and should not be disturbed. This can be done by setting the boolean property canDisplayCampaigns
of Usabilla
to suit your needs.
Usabilla.canDisplayCampaigns = false
Setting it to true
will allow the SDK to display any campaign when it triggers.
Setting it to false
will prevent all campaigns from being displayed.
Even when canDisplayCampaigns
is set to false
, the SDK continues to receive all events. If a campaign happens to trigger, it won't be displayed nor delayed: that event instance will be lost.
By default, canDisplayCampaigns
is set to true
.
If one or more of your campaigns trigger when the canDisplayCampaigns
property is set to false
and later on changed to true
, the SDK will not display the campaign. The reasoning is because this moment, later in time, might be irrelevant to display the campaign to the user.
It is possible to get information about the feedback the user has left and you will also be notified if the user has left the form without submitting it, simply by implementing:
func campaignDidClose(withFeedbackResult result: FeedbackResult, isRedirectToAppStoreEnabled: Bool) {}
Unlike the Passive feedback method, the campaigns method only returns one FeedbackResult and is called only once.
During development and testing, it might be useful to reset the status of your campaigns and allow them to be displayed again.
You can do so by calling Usabilla.resetCampaignData(completion: nil)
.
You can include a closure that will be executed when the SDK is done resetting campaign data.
This method will synchronize your data with the Usabilla server, so it will fetch all the new campaigns and remove the deactivated ones as well.
You can start collecting campaign results right after you create a new campaign in the Usabilla for Apps Campaign Editor. By default, new campaigns are marked as inactive. On the Usabilla for Apps Campaign Overview page, you can activate or deactivate an existing campaign at any moment to reflect your specific needs.
Moreover, you can update the content of your campaign (e.g. questions) at any time. Keep in mind that the changes you make to an existing active campaign might affect the integrity of the data you collect (different responses before and after a change).
Furthermore, you can also change the targeting options of a campaign. Keep in mind that updating the targeting options of an active campaign will reset any progression previously made on the user's device.
Aggregated campaign results are available for download from the Campaign Overview. Here you can download the results per campaign, in the CSV format.
Campaign results will contain the answers that your users provided. Responses from a campaign are collected and sent to Usabilla page by page. This means that even if a user decides to abandon the campaign halfway through, you will still collect valuable insights. When a user continues to the next page, then the results of the previous page are submitted to Usabilla. Besides campaign results showing the answers to your campaign questions, you will be able to view the device metadata and custom variables.
As for campaign results. Please note that editing the form of an existing campaign will affect the aggregated campaign results:
- Adding new questions to a form will add additional columns to the CSV file.
- Removing questions from an existing form will not affect the previously collected results. The associated column and its data will still be in the CSV file.
- Replacing the question type with a different question is also possible. When you give the same 'name' in the Usabilla for Apps Campaign Editor, then results are represented in the same column.
Passive feedback are feedback forms that are not triggered by events. They are mostly, but not necessarily, initiated by the user.
The SDK uses the Form ID you get from Usabilla after creating a new form to fetch and display the form inside your app.
A basic implementation of the SDK would be the following:
class SomeViewController: UIViewController, UsabillaDelegate {
override func viewDidLoad() {
super.viewDidLoad()
Usabilla.delegate = self
Usabilla.loadFeedbackForm("Form ID")
}
//Called when your form successfully load
func formDidLoad(form: UINavigationController) {
present(form, animated: true, completion: nil)
}
//Called when your forms can not be loaded. Returns a default form
func formDidFailLoading(error: UBError) {
//...
}
}
If you know you will need to display a feedback form when the user is offline, you can preload and cache it to make it available at any given moment.
To preload a form use
UsabillaFeedbackForm.preloadFeedbackForms(withFormIDs: ["FORM_ID_1", "FORM_ID_2"])
This will fetch the latest version of the form and cache it in the SDK.
When you will request that form, if there is no network connectivity, the SDK will use the cached version and your user will be able to submit his feedback
Feedback submitted while offline will be sent when connectivity is restored.
If you wish, you can empty the cache using
UsabillaFeedbackForm.removeCachedForms()
On iPad, the Passive feedback form has a presentation style set to formSheet by default. If you want to override this behavior and have a full screen display you can achieve it with:
func formDidLoad(form: UINavigationController) {
form.modalPresentationStyle = .fullScreen
present(form, animated: true, completion: nil)
}
It is possible to attach a screenshot to a feedback form.
You can take a screenshot at any moment calling
let image = Usabilla.takeScreenshot(self.view)
To attach the screenshot to the form, pass it as a parameter when calling
Usabilla.loadFeedbackForm("Form Id", screenshot: image)
Pass nil
as the screenshot
parameter if you don't want to have a screenshot of the current view.
Custom Screenshot & Sensitive Information
Instead of taking the screenshot using the Usabilla.takeScreenshot()
method, you can provide any image you wish by passing it as the image
parameter when calling Usabilla.loadFeedbackForm()
This will allow you to hide any user sensitive information by, for example, taking the screenshot yourself, removing all unwanted information and submitting the censored version.
It is possible to get information about the feedback the user has left and you will also be notified if the user has left the form without submitting it, simply by implementing:
func formDidClose(formID: String, withFeedbackResults results: [FeedbackResult], isRedirectToAppStoreEnabled: Bool) {
//...
}
This delegate method provides you with an array of FeedbackResult
because the user may submit the form multiple times and this method will be called only once for all the feedback sent.
struct FeedbackResult {
let rating: Int?
let abandonedPageIndex: Int?
var sent: Bool
}
The rating value is set as soon as the user interacts with it and will be reported even if the form is not submitted.
The abandonedPageIndex is only set if the user cancels the form before submission.
Example
func formDidClose(formID: String, with feedbackResults: [FeedbackResult], isRedirectToAppStoreEnabled: Bool) {
guard let feedback = feedbackResults.first else {
return
}
if feedback.sent == false {
let abandonedPageIndex = feedback.abandonedPageIndex
print("Hey why did you left the form here \(abandonedPageIndex)")
return
}
if let rating = feedback.rating {
if rating >= 4 && isRedirectToAppStoreEnabled {
// Prompt the user for rating and review
}
}
}
It is possible to customize the way the form is dismissed, you can achieve this by adding this line:
Usabilla.dismissAutomatically = false
and implement the formWillClose delegate method:
func formWillClose(form: UINavigationController, formID: String, withFeedbackResults results: [FeedbackResult], isRedirectToAppStoreEnabled: Bool) {
// handle your custom dismiss e.g: dismiss(animated: true, completion: nil)
}
Warning: by doing this the form will not dismiss by itself and you will be the only one responsible for its correct behavior. Also, the delegate method formDidClose
will not be called.
The SDK has an option to mask (on the back-end side) the data from input texts, specifically Text Input
and Text Area
. Please note that the an email input field is not being masked.
It matches a list of RegEx and replaces them by the "X" character by default.
The SDK has a setDataMasking
method that can be used as:
Usabilla.setDataMasking()
Usabilla.setDataMasking(masks: [String])
Usabilla.setDataMasking(masks: [String], maskCharacter: Character)
masks
is a list of RegExes to mask data in input fields. It uses the default RegExes that the SDK provides.
maskCharacter
is a character to replace the matched RegExes. By default it uses "X"".
The default RegExes that the SDK provides are: Email Addresses & Numbers
For email it uses:
[a-zA-Z0-9\+\.\_\%\-\+]{1,256}\@[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}(\.[a-zA-Z0-9][a-zA-Z0-9\-]{0,25})+
For Numbers with the length 4 or more
[0-9]{4,}
The default RegEx can be accessed by:
Usabilla.defaultDataMasks
You can pass along custom variables that will be attached to the feedback users send.
Custom variables are held in a dictionary object, in the public interface of the SDK, called customVariables
.
You can set custom variables using the public method
Usabilla.setCustomVariable(value: Any?, forKey: String)
or by simply modifying the dictionary object
Usabilla.customVariables["key"] = "value"
Since the SDK is using JSONSerialisation to convert the custom variables to JSON, its limitations have to be taken into account.
The value
of a custom variable must then be an instance NSString, NSNumber, NSArray, NSDictionary, or NSNull.
Trying to set an invalid object as a custom variable will result in that object not being set and in an error being printed in the console.
You can always check whether an object is considered valid or not by calling JSONSerialization.isValidJSONObject(object)
Custom variables are added as extra feedback data with every feedback item sent by the SDK, whether from a passive feedback or a campaign.
Custom variables can be used as targeting options, as long as the value
is a String.
To decide whether or not to prompt the user for a rating, you can read the information regarding the user's activity passed in the Submission callback or the Campaign submission callback
In the Usabilla web interface, it is possible to define whether a specific feedback form should prompt the user for a rating.
The SDK provides a way to programmatically dismiss all forms through the method:
let result = Usabilla.dismiss()
This will result in the Form or Campaign being removed. No delegate methods will get called eg. formDidClose
If there is a Form or a Campaign the method will return true, false otherwise.
It is possible to force a Campaign or Form to be presented in specific orientation, regardless of the device orientation, or the supported orientations for the Application.
Usabilla.orientation = .landscapeLeft
Set this property before presenting a Campaign or Form. It defaults to
Usabilla.orientation = .all
which should also be used to reset the properties, to follow the Applications settings for supported orientations.
It is possible to use custom images instead of the one provided natively in the SDK.
To do so, you must provide a list (or two, depending on what you want to achieve) of five UIImage
that will be used instead of the Usabilla's default emoticons.
The first element of the array should be the lowest or leftmost item, while the 5th element will be the highest or rightmost.
At the moment, the SDK does not perform any check to make sure the lists are valid.
You can provide only one list containing the selected version of the icons.
The images will be displayed with an alpha value of 0.5 when unselected, and with an alpha value of 1 when selected.
let a = UIImage(named: "1")!
let b = UIImage(named: "2")!
let c = UIImage(named: "3")!
let d = UIImage(named: "4")!
let e = UIImage(named: "5")!
Usabilla.theme.images.enabledEmoticons = [a, b, c, d, e]
You can provide two lists containing the selected and the unselected version of the icons.
The icons drawable will be selected from one of the two lists according to its state.
let enabled = createEnabledArray()
let disabled = createDisabledArray()
Usabilla.theme.images.enabledEmoticons = enabled
Usabilla.theme.images.disabledEmoticons = disabled
You can change the appearance of the star in the Star Rating by setting both star
and starOutline
in the UsabillaTheme.
Keep in mind that, in order to display the Star Rating in your form, you must first enable it in the Usabilla Web Interface.
Usabilla.theme.images.star = UIImage(named: "starFilled")!
Usabilla.theme.images.starOutline = UIImage(named: "starOutline")!
It is possible to change the font of the feedback form by setting the regular
and bold
properties of the UsabillaTheme.fonts
structure.
If they are not set the SDK will use the default system font.
Usabilla.theme.fonts.regular = UIFont(name: "Helvetica-LightOblique", size: 20)
Usabilla.theme.fonts.bold = UIFont(name: "Helvetica-Bold", size: 20)
All colors are set from the Usabilla website and not from the SDK. You can find a detailed explanation of the color's name and role in our knowledge base.
The only exception is for the header
color, used to change the color of the navigation bar.
You can set the header color by calling Usabilla.theme.colors.header = UIColor.red
before displaying the form.
For all the text that is not customizable in the web interface, you can provide your own translation using a .string
localized file inside your application.
This file also includes all the accessibility labels read when VoiceOver is enabled.
If you want to provide your own translation, you need to override all the keys in the default .string file.
The default file with the keys and the default text is the following:
///Default usabilla english localization
"usa_form_continue_button" = "Next";
"usa_form_close_button" = "Close";
"usa_form_required_field_error" = "Please check this field";
"usa_screenshot_placeholder" = "Add screenshot";
// Accessibility labels
"usa_mood_select_a_rating_out_of" = "select a rating out of";
"usa_accessibility_field_required" = "This field is required";
"usa_choose_from_options" = "Choose from %d options";
"usa_delete_screenshot" = "delete screenshot";
"usa_edit_screenshot" = "change screenshot";
"usa_powered_by_usabilla" = "powered by usabilla";
"usa_tap_to_visit_usabilla" = "tap to visit usabilla.com";
"usa_accessibility_button_label_continue" = "Continue";
// Emoticons
"usa_mood_hate" = "Hate";
"usa_mood_dislike" = "Dislike";
"usa_mood_neutral" = "Neutral";
"usa_mood_like" = "Like";
"usa_mood_love" = "Love";
// Stars
"usa_mood_one_star" = "1 star";
"usa_mood_two_star" = "2 stars";
"usa_mood_three_star" = "3 stars";
"usa_mood_four_star" = "4 stars";
"usa_mood_five_star" = "5 stars";
// checkbox & radio button
"usa_multiple_options_possible" = "Multiple options possible";
"usa_one_option_possible" = "One option possible";
"usa_selected" = "selected";
"usa_unselected" = "unselected";
// Added in SDK Version 6.4.0
//camera button
"usa_camera_navbar_left_button" = "Cancel";
// Screenshot anotation
"usa_retake_button_title" = "Retake";
"usa_back_button_title" = "Back";
"usa_add_button_title" = "Add";
"usa_done_button_title" = "Done";
"usa_back_button_library_title" = "Library";
"usa_library_title" = "Library";
"usa_edit_title" = "Edit";
"usa_add_title" = "Add photo";
"usa_camera_error_title" = "No access to camera";
"usa_camera_error_description" = "Allowing access lets you take photos to add to your feedback.";
"usa_camera_settings_title" = "Allow access to camera";
"usa_library_error_title" = "No access to library";
"usa_library_error_description" = "Allowing access lets you select a photo to add to your feedback.";
"usa_library_settings_title" = "Allow access to library";
Failure to override a key will display the key itself instead as the text.
If you want to use your custom .string file, you can do so by calling
Usabilla.localizedStringFile = "your_localization_file_name"
With the name of your file, without the .string extension.
If the user tries to set a custom screenshot, the SDK will ask for the permission to access the gallery.
We now also ask for camera access.
These privacy permissions are needed on the main app:
NSCameraUsageDescription
NSPhotoLibraryUsageDescription
Please make sure there is a description string for each of these properties
Refer to Apples technical document, on how to localize these
NOTE: If you haven’t enabled the ‘Show screenshot’ option in the Advanced settings panel of a form, the camera and the photo-library will not be displayed. But since your application (containing this SDK) has a feature that could use them, these privacy permissions must be include to pass App-store reviews. In that case, they will never be shown to your end users.
To integrate the SDK in your Obj-C application, follow the Apple official guidelines on how to use Swift and Objective-C in the Same Project.
A quick way to approach this problem is to create a Swift file from where you will handle your application. After creating the new file and having set up the Bridging Header, you can extend your existing view controllers inside the Swift class to seamlessly integrate the SDK in your app.
In this example you can see a ViewController in Obj-C:
#import "ViewController.h"
//Remember to import the auto-generated Swift header, otherwise, you won't see your Swift extension
#import "objctest-Swift.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)buttonPressed:(id)sender {
[self showForm];
}
@end
And its Swift extension, implementing the SDK:
import Usabilla
extension ViewController : UsabillaDelegate {
override open func viewDidLoad() {
super.viewDidLoad()
Usabilla.delegate = self
}
func formDidLoad(form: UINavigationController) {
present(form, animated: true)
}
func formDidFailLoading(error: UBError) {
//...
}
@objc public func showForm() {
Usabilla.loadFeedbackForm("Form ID")
}
}