-
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.
- Loading branch information
Showing
16 changed files
with
357 additions
and
56 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,17 @@ | ||
// Defines the common enum to use for event names across all analytics services | ||
export enum AnalyticsEventEnum { | ||
BOOKING, | ||
BOOKING_END, | ||
BOOKING_ADD_TIME, | ||
BOOKING_DEDUCT_TIME, | ||
BUILDING_SELECT | ||
} | ||
|
||
// Defines the common event names to use across all analytics services | ||
export const analyticsEventMap: { [key in AnalyticsEventEnum]: string } = { | ||
[AnalyticsEventEnum.BOOKING]: 'booking', | ||
[AnalyticsEventEnum.BOOKING_END]: 'bookingEnd', | ||
[AnalyticsEventEnum.BOOKING_ADD_TIME]: 'bookingAddTime', | ||
[AnalyticsEventEnum.BOOKING_DEDUCT_TIME]: 'bookingDeductTime', | ||
[AnalyticsEventEnum.BUILDING_SELECT]: 'buildingSelect' | ||
}; |
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]); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
frontend/src/analytics/googleAnalytics/googleAnalyticsEvents.ts
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,70 @@ | ||
import { AnalyticsEventEnum } from '../AnalyticsEvent'; | ||
import { Booking, Building, Room } from '../../types'; | ||
|
||
// Basic interface for all google analytics events | ||
export interface GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum; | ||
eventObject: object; | ||
} | ||
|
||
export class BookingEvent implements GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum = AnalyticsEventEnum.BOOKING; | ||
eventObject: object; | ||
|
||
constructor(room: Room, duration: number) { | ||
this.eventObject = { | ||
roomName: room.name, | ||
building: room.building, | ||
duration: duration | ||
}; | ||
} | ||
} | ||
|
||
export class BookingEndEvent implements GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum = AnalyticsEventEnum.BOOKING_END; | ||
eventObject: object; | ||
|
||
constructor(room: Room) { | ||
this.eventObject = { | ||
roomName: room.name, | ||
building: room.building | ||
}; | ||
} | ||
} | ||
|
||
export class BookingAddTimeEvent implements GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum = AnalyticsEventEnum.BOOKING_ADD_TIME; | ||
eventObject: object; | ||
|
||
constructor(booking: Booking) { | ||
this.eventObject = { | ||
roomName: booking.room.name, | ||
building: booking.room.building, | ||
bookingResources: booking.resourceStatus | ||
}; | ||
} | ||
} | ||
|
||
export class BookingDeductTimeEvent implements GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum = AnalyticsEventEnum.BOOKING_DEDUCT_TIME; | ||
eventObject: object; | ||
|
||
constructor(booking: Booking) { | ||
this.eventObject = { | ||
roomName: booking.room.name, | ||
building: booking.room.building, | ||
bookingResources: booking.resourceStatus | ||
}; | ||
} | ||
} | ||
|
||
export class ChooseBuildingEvent implements GoogleAnalyticsEvent { | ||
eventType: AnalyticsEventEnum = AnalyticsEventEnum.BUILDING_SELECT; | ||
eventObject: object; | ||
|
||
constructor(building: Building) { | ||
this.eventObject = { | ||
buildingName: building.name | ||
}; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
frontend/src/analytics/googleAnalytics/googleAnalyticsService.ts
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,22 @@ | ||
import { analyticsEventMap } from '../AnalyticsEvent'; | ||
import { GoogleAnalyticsEvent } from './googleAnalyticsEvents'; | ||
|
||
function isGAEnabled(): boolean { | ||
// @ts-ignore | ||
if (!window.gtag) { | ||
console.log('Google Analytics is not enabled!'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function triggerGoogleAnalyticsEvent(event: GoogleAnalyticsEvent) { | ||
if (isGAEnabled()) { | ||
// @ts-ignore | ||
window.gtag( | ||
'event', | ||
analyticsEventMap[event.eventType], | ||
event.eventObject | ||
); | ||
} | ||
} |
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
Oops, something went wrong.