@sheerid/jslib-nightly
Version:
SheerID JavaScript Library
218 lines (216 loc) • 8.37 kB
TypeScript
import { VerificationStep, VerificationResponse, WithCoreFields } from '../types/types';
export declare enum isTestValues {
TRUE = "true",
FALSE = "false"
}
export declare const testRequestEmailDomains: string[];
export declare enum EventName {
ASR_SELECTED = "AsrSelected",// Add School Request clicked by user
FORM_PASTE = "FormPaste",// When content is pasted into the form!
INVALID_FORM_SUBMIT = "InvalidFormSubmit",// When a form is submitted but has validation errors
STEP_SEEN = "StepSeen",// when a consumer first sees a step (once)
STEP_SUBMITTED = "StepSubmitted",// when a consumer submits the step (but before we know that Platform gave a 2xx rsp)
STEP_ACCEPTED = "StepAccepted",// when platform responds w/ 2xx response
ORG_SELECTED = "OrgSelected",// an org was clicked from the list
ORGS_DISPLAYED = "OrgsDisplayed",// orgs are listed/shown to the user
VIEW_EXPERIMENT = "ViewExperiment",// describe the variation for an experiment. Usually a Launch Darkly experiment
/** @deprecated Use STEP_SEEN instead */
COLLECT_STARTED = "CollectStarted",// Collect step is started
/** @deprecated Use STEP_SUBMITTED instead */
COLLECT_SUBMITTED = "CollectSubmitted",// Collect step's submit button is clicked
/** @deprecated use specifically-named events instead, e.g. "LCP" event */
PERFORMANCE = "Performance",
USER_PROPERTIES = "user_properties",
/** @deprecated use specifically-named events instead, e.g. "CollectSubmitted" event */
VERIFICATION = "Verification",
VERIFICATION_HELP = "VerificationHelp"
}
export declare enum CustomDimensionNames {
/** @deprecated - Age is potentially sensitive data and should not be sent HC-1117 */
age = "age",
jslibVersionActual = "jslibVersionActual",
programId = "programId",
segment = "segment",
subSegment = "subSegment",
testMode = "testMode",// whether the program is in test mode, or not
testRequest = "testRequest",// true if using an email with `@sheerid.com` when filling in the form
verificationId = "verificationId",
flags = "flags",// a JSON string of all experiment flags
options = "options",// a csv of the options that were set in setOptions
flag = "flag",// deprecated - use "flags" which is a user-scoped dimension
step = "step",// the verification step on which the event occurred
stepAction = "step_action",// deprecated - use a descriptive event name instead
/**
* An identifier for a value of this event. Could be the form element name or another
* unique identifier. Not to be confused with the event name itself.
*/
identifier = "id",
verificationHelpStatus = "verificationHelpStatus"
}
/**
* Metrics should be somewhat generic but make sense within the context of a specific event.
* e.g. "event duration" is generic, could be used for a page load event or a organization
* search event or a user reading terms and conditions event.
*/
export declare enum CustomMetricNames {
/**
* The duration of an event. See our event documentation for context on what this measures, exactly
* Unit: milliseconds
*/
EVENT_DURATION = "eventDuration",
/**
* For any search related event, how many characters are in the input at the time of search
*/
QUERY_LENGTH = "queryLength",
/**
* For any search related event, which spot in the result list was chosen?
* Lower numbers are higher on the list (1 at top). A user selecting rank 1 is ideal.
*/
SELECTED_RESULT_RANK = "selectedResultRank",
/**
* For any event, especially search events, the number of results returned to the user
*/
NUMBER_OF_RESULTS = "numberOfResults",
/**
* For any event, number of times a user had to "re-work" something (a frustration metric)
* e.g. in a search input box, number of times user pressed backspace or delete
*/
NUMBER_REWORKS = "numberReworks",
/**
* @deprecated
* @TODO Change this to an event name
*
* Specific to step loading
* Unit: milliseconds
*/
INITIAL_STEP_LOAD = "initialStepLoad",
/**
* @deprecated
* @TODO Change this to an event name
*
* For any event (either entire page load or a portion of a page load) the loading time
* before most content is painted in-browser
* Unit: milliseconds
*/
LCP = "largestContentfulPaint"
}
interface GaEvent {
eventName: EventName;
params: {
[]: string | number;
};
}
/**
* GA event for after a search returns results and they display to the user
*/
export interface OrgsDisplayedEvent extends GaEvent {
eventName: EventName.ORGS_DISPLAYED;
params: {
[]: number;
/**
* How long (ms) before showing organization result list to user
*/
[]: number;
[]: number;
};
}
/**
* GA event for when an org is selected by the user
*/
export interface OrgSelectedEvent extends GaEvent {
eventName: EventName.ORG_SELECTED;
params: {
[]: number;
[]: number;
[]: number;
/**
* How long (ms) between first keypress and an org selected
*/
[]: number;
[]: number;
};
}
/**
* GA event for when Add School Request is clicked
*/
export type AsrEvent = {
eventName: EventName.ASR_SELECTED;
params: {
[]: number;
[]: number;
/**
* Time since first letter typed into the search input
*/
[]: number;
[]: number;
};
};
export type PasteEvent = {
eventName: EventName.FORM_PASTE;
params: {
[]: number;
[]: string;
};
};
/**
* Collect step first shown to user after page loaded
*/
export type CollectStepStartEvent = {
eventName: EventName.COLLECT_STARTED;
params: {};
};
/**
* Collect step submitted
*/
export type CollectStepSubmitEvent = {
eventName: EventName.COLLECT_SUBMITTED;
params: {
/**
* Amount of milliseconds it took to fill out the form and click submit
*/
[]: number;
};
};
/**
* GA event for when the verificationHelp endpoint is used
*/
export type VerificationHelpEvent = {
eventName: EventName.VERIFICATION_HELP;
params: {
[]: string;
[]: number;
};
};
export declare const recordGaEvent: (event: GaEvent) => Promise<void>;
/**
* Sets or a user dimension
*/
export declare const setUserDimension: (dimensionName: CustomDimensionNames, value: string) => void;
/**
* Sets or updates user dimensions for all subsequent events
*/
export declare const recordVerificationResponse: (verificationResponse: VerificationResponse) => void;
/**
* Sets a user dimension
* @deprecated Use setUserDimension instead
*/
export declare const setDimension: (dimensionName: CustomDimensionNames, value: string) => void;
export declare const setGaDimensionTestRequest: (viewModel: WithCoreFields) => void;
export declare function observePerformanceMetrics(): void;
/**
* Record a Verification Step event
* @deprecated use recordGaEvent() instead
*/
export declare const recordEvent: (step: VerificationStep, stepAction?: string) => void;
/** @deprecated Use recordGaEvent() instead */
export declare const recordPerformanceMetric: (name: CustomMetricNames, value: number) => void;
/**
* An event that is sent once a user sees a variant of an experiment flag
* Potentially fired multiple times per user/session
*
* Records the "flag" dimension value as a string like: "{flagName}:{flagValue}"
* OR
* records as just "{flagName}" (old) for backward compatibility w/ ExperimentComponent if you omit the 2nd arg
*/
export declare const recordViewExperimentEvent: (flagName: string, flagValue?: string) => void;
export {};