Merge pull request #33600 from aaronbeall/pendo-io-agent

Added Pendo.io Agent JS definitions
This commit is contained in:
Nathan Shively-Sanders
2019-03-07 16:38:36 -08:00
committed by GitHub
4 changed files with 269 additions and 0 deletions
+167
View File
@@ -0,0 +1,167 @@
// Type definitions for non-npm package Pendo.io Agent 2.16
// Project: https://www.pendo.io/
// Definitions by: Aaron Beall <https://github.com/aaronbeall>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
declare namespace pendo {
interface Identity {
visitor: Visitor;
account?: Account;
}
type Metadata = Record<string, string | number | undefined>;
interface Visitor extends Metadata {
id: string;
}
interface Account extends Metadata {
id?: string;
}
interface InitOptions extends Identity {
apiKey?: string;
excludeAllText?: boolean;
excludeTitle?: boolean;
disablePersistence?: boolean;
guides?: {
delay?: boolean;
disable?: boolean;
timeout?: number;
tooltip?: {
arrowSize?: number;
}
};
events?: EventCallbacks;
}
interface EventCallbacks {
ready?(): void;
guidesLoaded?(): void;
guidesFailed?(): void;
}
interface Pendo {
// Initialization and Identification
initialize(options: InitOptions): void;
identify(visitorId: string, accountId?: string): void;
identify(identity: Identity): void;
isReady(): boolean;
flushNow(): Promise<any>;
updateOptions(visitorMetadata: Metadata): void;
getVersion(): string;
getVisitorId(): string;
getAccountId(): string;
getCurrentUrl(): string;
// Guides and Guide Center
findGuideByName(name: string): Guide | void;
findGuideById(id: string): Guide | void;
showGuideByName(name: string): void;
showGuideById(id: string): void;
toggleLauncher(): void;
removeLauncher(): void;
// Troubleshooting
loadGuides(): void;
startGuides(): void;
stopGuides(): void;
// Debugging
enableDebugging(): void;
disableDebugging(): void;
isDebuggingEnabled(coerce?: false): "Yes" | "No";
isDebuggingEnabled(coerce: true): boolean;
debugging: Debugging;
// Events
events: Events;
track(trackType: string, metadata?: Metadata): void;
// Guide Events
onGuideAdvanced(step?: GuideStep): void;
onGuideAdvanced(steps: { steps: number }): void;
onGuidePrevious(step?: GuideStep): void;
onGuideDismissed(step?: GuideStep): void;
onGuideDismissed(until: { until: "reload" }): void;
// Other
validateInstall(): void;
dom(input: any): HTMLElement; // TODO
}
interface Debugging {
getEventCache(): any[]; // TODO
getAllGuides(): Guide[];
getAutoGuides(): { auto: Guide[]; override: Guide[] };
getBadgeGuides(): Guide[];
getLauncherGuides(): Guide[];
}
type Events = {
[K in keyof EventCallbacks]-?: (callback: EventCallbacks[K]) => Events;
};
interface Guide {
createdByUser: User;
createdAt: number;
lastUpdatedByUser: User;
lastUpdatedAt: number;
kind: string;
rootVersionId: string;
stableVersionId: string;
id: string;
name: string;
state: "published" | "staged" | "draft" | "disabled";
launchMethod: "api" | "automatic" | "badge" | "dom" | "launcher";
isMultiStep: boolean;
steps: GuideStep[];
attributes: {
type: string;
device: { desktop: boolean; mobile: boolean; type: "desktop" | "mobile" };
badge: any;
priority: number;
launcher: { keywords: string[] };
};
audience: any[]; // TODO
audienceUiHint: { filters: any[] }; // TODO
resetAt: number;
publishedAt: number;
}
interface User {
id: string;
username: string;
first: string;
last: string;
role: number;
userType: string;
}
interface GuideStep {
id: string;
guideId: string;
type: string;
elementPathRule: string;
contentType: string;
contentUrl?: string;
contentUrlCss?: string;
contentUrlJs?: string;
rank: number;
advanceMethod: "button" | "programatic" /* sic */ | "element";
thumbnailUrls?: string;
attributes: {
height: number;
width: number;
autoHeight: boolean;
position: string;
css: string;
variables: any;
};
lastUpdatedAt: number;
resetAt: number;
}
}
declare const pendo: pendo.Pendo;
@@ -0,0 +1,77 @@
// Examples from: https://developers.pendo.io/docs/?bash#agent-api
pendo.initialize({
visitor: {
id: "PUT_VISITOR_ID_HERE",
name: "Neo",
email: "neo@thematrix.io",
role: "godlike"
},
account: {
id: "PUT_ACCOUNT_ID_HERE",
name: "CorpSchmorp"
}
});
pendo.identify(
"PUT_VISITOR_ID_HERE",
"PUT_ACCOUNT_ID_HERE"
);
pendo.identify({
visitor: {
id: "PUT_VISITOR_ID_HERE",
name: "Neo",
email: "neo@thematrix.io",
role: "godlike"
},
account: {
id: "PUT_ACCOUNT_ID_HERE",
name: "CorpSchmorp"
}
});
pendo.debugging.getEventCache();
pendo.events
.ready(() => {
// Do something once `pendo.isReady()` would return `true`
})
.guidesLoaded(() => {
// Do something when Guides load
})
.guidesFailed(() => {
// Do something when Guides fail to load
});
pendo.initialize({
apiKey: 'YOUR_API_KEY',
visitor: { id: "" },
account: { id: "" },
events: {
ready() {
// Do something when pendo is initialized
}
}
});
pendo.track("User Registered", {
userId: "user.id",
plan: "user.plan",
accountType: "Facebook"
});
try {
throw new Error();
} catch (error) {
pendo.track("JIRA-12345--error-tripped", {
message: error.message,
stack: error.stack
});
}
pendo.dom("").closest('._pendo-guide-next_');
pendo.onGuideAdvanced();
pendo.onGuideAdvanced({ steps: 2 });
pendo.onGuideDismissed();
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"pendo-io-browser-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }