import { JSONStorage } from "node-localstorage" ; import { app } from "electron" ; import ua from "universal-analytics" ; import { v4 as uuidv4 } from 'uuid' ; const DEV_UA_CODE = 'UA-197149286-1' ; const PROD_UA_CODE = 'UA-99317940-17' ; function getGAnalyticsCode ( ) { const isDev = process . env . NODE_ENV === 'development' ; return isDev ? DEV_UA_CODE : PROD_UA_CODE ; } const path = app . getPath ( 'userData' ) ; const nodeStorage = new JSONStorage ( path ) ; const userId = nodeStorage . getItem ( 'userid' ) || uuidv4 ( ) ; nodeStorage . setItem ( 'userid' , userId ) ; const trackingCode = getGAnalyticsCode ( ) ; const agent = ua ( trackingCode , userId ) ; function getUACode ( ) { return nodeStorage . getItem ( 'userid' ) || uuidv4 ( ) ; } function actionEvent ( category , action , label , value ) { try { agent . event ( { ec : category , ea : action , el : label , ev : value , } ) . send ( ) ; } catch ( e ) { } } function transactionEvent ( transactionId , value , transactionType ) { try { agent . transaction ( transactionId , value , '' , '' , transactionType ) . item ( value , 1 ) . send ( ) ; } catch ( e ) { } } function pageView ( pageName ) { try { agent . pageview ( pageName ) . send ( ) ; } catch ( e ) { } } module . exports = { getUACode , getGAnalyticsCode , actionEvent , transactionEvent , pageView } ;