Link

Setup

Table of contents

  1. Application screens
  2. Events
  3. User traits
  4. Reset
  5. Listeners

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:

  • Screen
  • Event
  • User attributes
  • Language
  • Known user
  • Operating system

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

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.

Kotlin Java Swift Objective-C

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

Events

You can log custom user events throughout your application. They can later be used in Survicate panel to trigger your surveys. Events trigger surveys instantly after ocurring in your app.

Kotlin Java Swift Objective-C

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(name: "userPressedPurchase")
}
- (IBAction)didPressButton:(id)sender {
    [[Survicate shared] invokeEventWithName:@"userPressedPurchase"];
}

User traits

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.

Kotlin Java Swift Objective-C

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"];

Please keep in mind that user traits are cached, you only have to provide them once, e.g. when user logs in, not after each init(). You can also change their values at any time (which may potentially trigger showing the survey).


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).

Kotlin Java Swift Objective-C

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

Listeners

SDK provides a number of listeners that you might find useful to trigger certain actions in your application based on the user’s actions:

  • Survey displayed - occurs when survey gets loaded and appears in user’s interface
  • Question answered - this event is triggered after a response submitted to each question
  • Survey closed - appears after user closes the survey using the close button
  • Survey completed - occurs when user responds to their last question and therefore finishes a survey

Kotlin Java Swift Objective-C

Survicate.setEventListener(object: SurvicateEventListener {
    override fun onSurveyDisplayed(surveyId: String) {
        Toast.makeText(this@MainActivity, "on survey displayed", Toast.LENGTH_SHORT).show()
    }
    override fun onQuestionAnswered(surveyId: String, questionId: Long, answer: SurvicateAnswer) {
        Toast.makeText(this@MainActivity, "on question answered", Toast.LENGTH_SHORT).show()
    }
    override fun onSurveyClosed(surveyId: String) {
        Toast.makeText(this@MainActivity, "on survey closed", Toast.LENGTH_SHORT).show()
    }
    override fun onSurveyCompleted(surveyId: String) {
        Toast.makeText(this@MainActivity, "on survey completed", Toast.LENGTH_SHORT).show()
    }
})
Survicate.setEventListener(new SurvicateEventListener() {
    @Override
    public void onSurveyDisplayed(@NonNull String surveyId) {
        Toast.makeText(MainActivity.this, "on survey displayed", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onQuestionAnswered(@NonNull String surveyId, long questionId, @NonNull SurvicateAnswer answer) {
        Toast.makeText(MainActivity.this, "on question answered", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onSurveyClosed(@NonNull String surveyId) {
        Toast.makeText(MainActivity.this, "on survey closed", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onSurveyCompleted(@NonNull String surveyId) {
        Toast.makeText(MainActivity.this, "on survey completed", Toast.LENGTH_SHORT).show();
    }
});
class YourClassName{
    // ...
        Survicate.shared.initialize()
        Survicate.shared.delegate = self
    // ...
}

extension YourClassName: SurvicateDelegate {
    func surveyDisplayed(surveyId: String) {
        print("DELEGATE survey_displayed \(surveyId)")
    }

    func questionAnswered(surveyId: String, questionId: Int, answer: SurvicateAnswer) {
        print("DELEGATE question_answered \(surveyId) \(questionId) \(answer)")
    }

    func surveyCompleted(surveyId: String) {
        print("DELEGATE survey_completed \(surveyId)")
    }

    func surveyClosed(surveyId: String) {
        print("DELEGATE survey_closed \(surveyId)")
    }
}


@interface AppDelegate () <SurvicateDelegate>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...
    [[Survicate shared] initialize];
    [[Survicate shared] setDelegate:self];
// ...
}

- (void)questionAnsweredWithSurveyId:(NSString * _Nonnull)surveyId questionId:(NSInteger)questionId answer:(SurvicateAnswer * _Nonnull)answer {
    NSLog(@"DELEGATE questionAnsweredWithSurveyId: %@, questionId: %ld, answer: %@", surveyId, (long)questionId, answer);
}

- (void)surveyClosedWithSurveyId:(NSString * _Nonnull)surveyId {
    NSLog(@"DELEGATE surveyClosedWithSurveyId: %@", surveyId);
}

- (void)surveyCompletedWithSurveyId:(NSString * _Nonnull)surveyId {
    NSLog(@"DELEGATE surveyCompletedWithSurveyId: %@", surveyId);
}

- (void)surveyDisplayedWithSurveyId:(NSString * _Nonnull)surveyId {
    NSLog(@"DELEGATE surveyDisplayedWithSurveyId: %@", surveyId);
}

Note: Our React Native library doesn’t support listeners yet.

SurvicateAnswer object properties

Property Type Description
type string Answer type.
id integer Answer ID. Applicable only for type = [‘single’, ‘smiley_scale’, ‘dropdown_list’].
ids integer[] Array of answer IDs. Applicable only for type = [‘multiple’].
value string Context value of the answer. Applicable only for type = [‘text’, ‘nps’, ‘date’, ‘rating’].

Note: at the moment we support passing the id, ids and value properties only for the cases enlisted in the table above. Therefore, expect that there might be answer objects that consist only of the type property.

← Installation Changelog →