Add telemetry for OpenTerminal success/failure (#192)

* Add telemetry for OpenTerminal success/failure

* Address review comments
This commit is contained in:
Tanuj Mittal
2020-09-11 15:42:55 -07:00
committed by GitHub
parent c401f88aae
commit 83b13de685
3 changed files with 48 additions and 18 deletions

View File

@@ -48,16 +48,31 @@ export function sendCachedDataMessage<TResponseDataModel>(
export function sendMessage(data: any): void {
if (canSendMessage()) {
window.parent.postMessage(
{
signature: "pcIframe",
data: data
},
window.document.referrer
);
const dataExplorerWindow = getDataExplorerWindow();
if (dataExplorerWindow) {
dataExplorerWindow.parent.postMessage(
{
signature: "pcIframe",
data: data
},
dataExplorerWindow.document.referrer
);
}
}
}
const getDataExplorerWindow = (): Window => {
// Traverse up the window to find a window with `dataExplorerPlatform` property
let dataExplorerWindow: Window = window;
// TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet
// eslint-disable-next-line @typescript-eslint/no-explicit-any
while (!(dataExplorerWindow as any).dataExplorerPlatform && dataExplorerWindow.parent) {
dataExplorerWindow = dataExplorerWindow.parent;
}
return dataExplorerWindow;
};
export function canSendMessage(): boolean {
return window.parent !== window;
}