-
Notifications
You must be signed in to change notification settings - Fork 0
/
survicate_widget.d.ts
81 lines (70 loc) · 2.54 KB
/
survicate_widget.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
type CallbackType = (surveyId: string, answer?: any) => void;
type QuestionAnsweredCallback = (surveyId: string, questionId: number, answer: any) => void;
type AttributeValue = string | number | boolean | Date;
interface VisitorAttributes {
[key: string]: AttributeValue;
}
export type CallbackTypes = CallbackType | QuestionAnsweredCallback;
export enum SurveyType {
WidgetSurvey = 'WidgetSurvey',
PageSurvey = 'PageSurvey',
MobileSurvey = 'MobileSurvey',
FeedbackButton = 'FeedbackButton',
IntercomSurvey = 'IntercomSurvey'
}
export interface ShowSurveyOptions {
forceDisplay?: true;
displayMethod?: AppearMethodApi;
displayOptions?: {
delay?: number;
scrolledPercentage?: number;
};
}
export enum AppearMethodApi {
immediately = 'immediately',
delayed = 'delayed',
exitIntent = 'exitIntent',
scroll = 'onScroll',
}
export enum ApiEvents {
questionAnswered = 'question_answered',
surveyDisplayed = 'survey_displayed',
surveyCompleted = 'survey_completed',
surveyClosed = 'survey_closed',
}
export interface ConfigModel {
disableTargeting?: true;
nonce?: string;
traits?: {[key: string]: any};
workspaceKey: string;
}
export interface SurveyApi {
addEventListener: (event: ApiEvents, callback: CallbackTypes) => number | void;
destroyVisitor: (callback?: () => void) => void;
disableTargeting?: boolean;
getSurvey: () => Record<string, Record<string, string>>;
getVisitorId: (surveyType?: SurveyType) => string;
invokeEvent: (eventName: string, eventProperties?: Record<string, string>) => void;
removeEventListener: (eventId: number | ApiEvents) => void;
retarget: () => void;
setVisitorTraits: (attributes: VisitorAttributes) => void;
showSurvey: (id: string, options: ShowSurveyOptions) => boolean;
traits?: VisitorAttributes;
}
declare const Survicate: {
ApiEvent: typeof ApiEvents;
AppearMethod: typeof AppearMethodApi;
addEventListener: (event: ApiEvents, callback: CallbackTypes) => number | void;
destroyVisitor: (callback?: () => void) => void;
disableTargeting?: boolean;
getSurvey: () => Record<string, Record<string, string>>;
getVisitorId: (surveyType?: SurveyType) => string;
init: (config: ConfigModel) => Promise<null | void>;
invokeEvent: (eventName: string, eventProperties?: Record<string, string>) => void;
removeEventListener: (eventId: number | ApiEvents) => void;
retarget: () => void;
setVisitorTraits: (attributes: VisitorAttributes) => void;
showSurvey: (id: string, options: ShowSurveyOptions) => boolean;
traits?: VisitorAttributes;
};
export default Survicate;