import { IAnalytics , IEventArgs , TraitsMap , IPageEvent , IAnalyticsUser } from "../IAnalytics" ; import { Dictionaries } from "polar-shared/src/util/Dictionaries" ; import onlyDefinedProperties = Dictionaries . onlyDefinedProperties ; export class CannyAnalytics implements IAnalytics { private cannyClient = createCannyClient ( ) ; private identification : ICannyUserData | undefined = undefined ; public constructor ( ) { } public event ( evt ) { } public event2 ( event , data ? ) { } public page ( event ) { } public identify ( user ) { if ( ! this . cannyClient ) { console . warn ( "No Canny client" ) ; return ; } this . identification = onlyDefinedProperties ( { email : user . email , name : user . displayName , id : user . uid , avatarURL : user . photoURL , created : user . created , customFields : { } } ) ; if ( this . identification ) { this . cannyClient . identify ( this . identification ) ; } } public traits ( traits ) { if ( ! this . cannyClient ) { console . warn ( "No Canny client" ) ; return ; } if ( this . identification ) { const newIdentification = { ... this . identification , customFields : { ... this . identification . customFields , ... traits } } ; this . identification = newIdentification ; this . cannyClient . identify ( this . identification ) ; } } public version ( version ) { } public heartbeat ( ) { } public logout ( ) { this . identification = undefined ; } } declare var window ; export type ICannyCustomFields = { [ key ] : string | number | Date ; } ; export interface ICannyUserData { readonly name ? : string ; readonly id : string ; readonly email : string ; readonly avatarURL ? : string ; readonly customFields : ICannyCustomFields ; } export interface ICannyData { appID : string ; user : ICannyUserData ; } export interface ICannyClient { readonly identify : ( data : ICannyUserData ) => void ; } export function createCannyClient ( ) { const appID = '6028141fa9c2061014659f73' ; if ( window . Canny ) { function doIdentify ( data ) { window . Canny ( 'identify' , data ) ; } function identify ( user ) { doIdentify ( { appID , user } ) ; } return { identify } ; } return undefined ; }