NAV Navbar
Kotlin Java Swift Objective-C

Mobile SDK

Introduction

The Survicate Mobile SDK allows you to survey specific groups of your mobile app users to understand their needs, expectations, and objections. This SDK is maintained by Survicate.

We support both Android and iOS platform. We have language bindings in Kotlin, Java, Swift and Objective-C! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Installation

Mobile SDK works on:

To use this SDK, you need an account at survicate.com. Sign up for free and find your workspace key in Tracking Code section.

Android

Project's build.gradle

allprojects {
    repositories {
        // ...
        maven { url 'https://repo.survicate.com' }
    }
}

App's build.gradle

dependencies {
    // ...
    implementation 'com.survicate:survicate-sdk:1.+'
}

AndroidManifest.xml

<application
    android:name=".MyApp"
>
    <!-- ... -->
    <meta-data android:name="com.survicate.surveys.workspaceKey" android:value="YOUR_WORKSPACE_KEY"/>
</application>

Application class

import android.app.Application
import com.survicate.surveys.Survicate

class MyApp : Application() {
    override fun onCreate() {
        super.onCreate()
        Survicate.init(this)
    }
}   
import android.app.Application;
import com.survicate.surveys.Survicate;

public class MyApp extends Application {
  @Override public void onCreate() {
    super.onCreate();
    Survicate.init(this);
  }
}   
// N/A
// N/A

We recommend using maven repository to get Survicate SDK.

  1. Define https://repo.survicate.com maven repository in project's build.gradle file. Make sure that repository is defined in allprojects section, not buildscript.
  2. Add com.survicate:survicate-sdk:1.+ dependency to your app's build.gradle file.
  3. Configure your workspace key in AndroidManifest.xml file. Create meta-data: com.survicate.surveys.workspaceKey.
  4. Initialize the SDK in your application class using init() method. If your project don't have custom application class yet, you'll need to create one. Make sure that your custom application class is defined in AndroidManifest.xml.

iOS

Podfile

platform :ios, '10.0'

target 'MyApp' do
    pod 'Survicate'
end    

AppDelegate class

// N/A
// N/A
// ...
import Survicate

class AppDelegate: UIResponder, UIApplicationDelegate {
    // ...
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        Survicate.shared.initialize()
        return true
    }
}
// ...
@import Survicate;

@implementation AppDelegate
// ...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[Survicate shared] initialize];
    return YES;
}
@end

We recommend using CocoaPods to get Survicate SDK.

  1. Define pod in your Podfile and run pod install.
  2. Add workspace key to your Info.plist file.
    • Create Survicate Dictionary.
    • Define WorkspaceKey String in Survicate Dictionary. Your Info.plist file should looks like this: Info.plist example
  3. Initialize the SDK in your AppDelegate class using initialize method.

Make sure that import Survicate line exists in all classes where you call SDK methods.

React Native

Feel free to use React Native bindings that are available under MIT License.

Setup

Survicate gives you the ability to send targeted surveys to your users within your app in a simple, easy, and fast way for you as well as Survicate application users. Within Survicate Panel you can choose criteria that your users have to meet in order for the surveys to appear in different ways. The users matching the conditions will see the survey automatically. You can set the criteria to be custom user attributes or user events you created.

Available conditions:

Make sure to list all the screens and events described in your application. Once you got this covered, you or any person responsible for creating and managing surveys will be able to trigger them from Survicate panel with no need for you to update the application.

Application screens

class PurchaseSuccessActivity : Activity() {

    val SCREEN_NAME = "purchaseSuccess"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // ...
        Survicate.enterScreen(SCREEN_NAME)
    }

    override fun onDestroy() {
        super.onDestroy()
        Survicate.leaveScreen(SCREEN_NAME)        
    }
}
public class PurchaseSuccessActivity extends Activity {

    public static final String SCREEN_KEY = "purchaseSuccess";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // ...
        Survicate.enterScreen(SCREEN_KEY);
    }

    @Override
    protected void onDestroy(){
        super.onDestroy();
        Survicate.leaveScreen(SCREEN_KEY);
    }

}
class PurchaseSuccessViewController: UIViewController {

    static var SCREEN_KEY: String = "purchaseSuccess"

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        Survicate.shared.enterScreen(SCREEN_KEY)
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        Survicate.shared.leaveScreen(SCREEN_KEY)
    }

}
@implementation PurchaseSuccessViewController

- (void)viewWillAppear:(BOOL)animated {  
  [super viewWillAppear:animated];
  [[Survicate shared] enterScreenWithValue:@"purchaseSuccess"];
}

-(void)viewWillDisappear:(BOOL)animated {  
  [super viewWillDisappear:animated];  
  [[Survicate shared] leaveScreenWithValue:@"purchaseSuccess"];  
}

@end

A survey can appear when your application user is viewing a specific screen. As an example, a survey can be triggered to show up on the home screen of the application, after a user spends there more than 10 seconds. To achieve such effect, you need to send information to Survicate about user entering and leaving a screen.

Events

button.setOnClickListener {
    Survicate.invokeEvent("userPressedPurchase")
}
purchaseBtn.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // ...
        Survicate.invokeEvent("userPressedPurchase");
    }
});
@IBAction func didPressButton(_ sender: Any) {
    Survicate.shared.invokeEvent("userPressedPurchase")
}
- (IBAction)didPressButton:(id)sender {
    [[Survicate shared] invokeEventWithName:@"userPressedPurchase"];
}

You can log custom user events throughout your application. They can later be used to trigger the survey.

User traits

val traits = ArrayList<UserTrait>()
traits.add(UserTrait.UserId("someUserId"))
traits.add(UserTrait.FirstName("John"))
traits.add(UserTrait("eyes", "blue"))
Survicate.setUserTraits(traits)

// or just
Survicate.setUserTrait(UserTrait.UserId("someOtherUserId"))
List<UserTrait> traits = new ArrayList<>();
traits.add(new UserTrait.UserId("someUserId"));
traits.add(new UserTrait.FirstName("John"));
traits.add(new UserTrait("eyes", "blue"));
Survicate.setUserTraits(traits);

// or just
Survicate.setUserTrait(new UserTrait.UserId("someOtherUserId"));
let traits: [UserTrait] = [
    UserTrait.userId("someUserId"),
    UserTrait.firstName("John"),
    UserTrait(withName: "eyes", value: "blue")
)
Survicate.shared.setUserTraits(traits: traits)

// or just
Survicate.shared.setUserTrait(.userId("someOtherUserId"))
[[Survicate shared] setUserTraitsWithNamesAndValues:@{
    @"user_id": @"someUserId",
    @"first_name": @"John",
    @"eyes": @"blue"
}];

// or just
[[Survicate shared] setUserTraitWithName:@"user_id" value:@"someOtherUserId"];

You can assign custom attributes to your users. Those attributes can later be used to trigger the survey or even filter the survey results within Survicate panel.

Reset

Survicate.reset()
Survicate.reset();
Survicate.shared.reset()
[Survicate.shared reset];

If you need to test surveys on your device, reset() method might be helpful. This method will reset all user data stored on your device (views, traits, answers).

Support

👋 If you bump into any problems or need more support, just start a conversation using Intercom in the bottom-right corner and you will be immediately routed to our Customer Support Engineers.