-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some utility classes for triggering analytics related events (o…
…nly for Booking at the moment). Also updated some config files.
- Loading branch information
1 parent
c8adaf1
commit ac02431
Showing
10 changed files
with
135 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum AnalyticsEventEnum { | ||
BOOKING, | ||
CANCEL_BOOKING | ||
} | ||
|
||
export const analyticsEventMap: { [key in AnalyticsEventEnum]: string } = { | ||
[AnalyticsEventEnum.BOOKING]: 'booking', | ||
[AnalyticsEventEnum.CANCEL_BOOKING]: 'cancelBooking' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { AnalyticsEventEnum, analyticsEventMap } from './AnalyticsEvent'; | ||
|
||
function isClarityEnabled(): boolean { | ||
// @ts-ignore | ||
if (!window.clarity) { | ||
console.log('Clarity is not enabled!'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function triggerClarityEvent(event: AnalyticsEventEnum) { | ||
if (isClarityEnabled()) { | ||
// @ts-ignore | ||
window.clarity('event', analyticsEventMap[event]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { AnalyticsEventEnum, analyticsEventMap } from './AnalyticsEvent'; | ||
|
||
export const analyticsGAEventMap: { [key in AnalyticsEventEnum]: object } = { | ||
[AnalyticsEventEnum.BOOKING]: { booking: 'Booked a Room' }, | ||
[AnalyticsEventEnum.CANCEL_BOOKING]: { | ||
cancelBooking: 'Cancelled a booked room' | ||
} | ||
}; | ||
|
||
function isGAEnabled(): boolean { | ||
// @ts-ignore | ||
if (!window.gtag) { | ||
console.log('Google Analytics is not enabled!'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function triggerGoogleAnalyticsEvent(event: AnalyticsEventEnum) { | ||
if (isGAEnabled()) { | ||
// @ts-ignore | ||
window.gtag( | ||
'event', | ||
analyticsEventMap[event], | ||
analyticsGAEventMap[event] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
import { defineConfig } from 'vite'; | ||
import { defineConfig, loadEnv } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import viteTsconfigPaths from 'vite-tsconfig-paths'; | ||
import svgr from 'vite-plugin-svgr'; | ||
import { VitePluginRadar } from 'vite-plugin-radar'; | ||
|
||
export default defineConfig({ | ||
// depending on your application, base can also be "/" | ||
base: './', | ||
plugins: [ | ||
// here is the main update | ||
react({ | ||
jsxImportSource: '@emotion/react', | ||
include: /\.(jsx|tsx)$/, | ||
babel: { | ||
plugins: ['@emotion/babel-plugin'] | ||
export default defineConfig(({ mode }) => { | ||
const env = loadEnv(mode, process.cwd(), ''); | ||
|
||
return { | ||
// depending on your application, base can also be "/" | ||
base: './', | ||
plugins: [ | ||
// here is the main update | ||
react({ | ||
jsxImportSource: '@emotion/react', | ||
include: /\.(jsx|tsx)$/, | ||
babel: { | ||
plugins: ['@emotion/babel-plugin'] | ||
} | ||
}), | ||
viteTsconfigPaths(), | ||
svgr({ | ||
svgrOptions: { exportType: 'named' }, | ||
include: '/**/*.svg' | ||
}), | ||
VitePluginRadar({ | ||
enableDev: true, | ||
// Google Analytics tag injection | ||
analytics: { | ||
id: env.VITE_GOOGLE_ANALYTICS_ID as string | ||
} | ||
}) | ||
], | ||
optimizeDeps: { | ||
include: ['@emotion/styled', '@mui/styled-engine'] | ||
}, | ||
server: { | ||
// this ensures that the browser opens upon server start | ||
open: true, | ||
// this sets a default port to 3000 | ||
port: 3000, | ||
proxy: { | ||
// with options: http://localhost:5173/api/bar-> http://jsonplaceholder.typicode.com/bar | ||
'/api': { | ||
target: 'http://localhost:8080', | ||
changeOrigin: false, | ||
secure: true | ||
// rewrite: (path) => path.replace(/^\/api/, '') | ||
} | ||
} | ||
}), | ||
viteTsconfigPaths(), | ||
svgr({ svgrOptions: { exportType: 'named' }, include: '/**/*.svg' }) | ||
], | ||
optimizeDeps: { | ||
include: ['@emotion/styled', '@mui/styled-engine'] | ||
}, | ||
server: { | ||
// this ensures that the browser opens upon server start | ||
open: true, | ||
// this sets a default port to 3000 | ||
port: 3000, | ||
proxy: { | ||
// with options: http://localhost:5173/api/bar-> http://jsonplaceholder.typicode.com/bar | ||
'/api': { | ||
target: 'http://localhost:8080', | ||
changeOrigin: false, | ||
secure: true | ||
// rewrite: (path) => path.replace(/^\/api/, '') | ||
}, | ||
build: { | ||
outDir: './build', | ||
rollupOptions: { | ||
external: ['**.test.ts'] | ||
} | ||
} | ||
}, | ||
build: { | ||
outDir: './build', | ||
rollupOptions: { | ||
external: ['**.test.ts'] | ||
} | ||
} | ||
}; | ||
}); |