Skip to content

Commit

Permalink
feat: add botDetected to amplitude events (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuroUhlar authored Oct 28, 2024
1 parent a33272e commit 88bcd34
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/client/analytics/Amplitude.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const EVENT_TYPE = 'Demo Page Viewed';
/**
* This is an Amplitude plugin that renames the Page view event_properties according to our analytics needs
*/
const renameEventPropertiesEnrichment: amplitude.Types.EnrichmentPlugin = {
name: 'rename-event-properties-enrichment',
const demoPageViewedEventPropertiesEnrichment = (botDetected: 'True' | 'False'): amplitude.Types.EnrichmentPlugin => ({
name: 'custom-event-properties-enrichment',
type: 'enrichment',
setup: async () => undefined,
execute: async (event) => {
Expand All @@ -26,10 +26,11 @@ const renameEventPropertiesEnrichment: amplitude.Types.EnrichmentPlugin = {
'Demo Page Path': originalEventProperties?.['[Amplitude] Page Path'],
'Demo Page Title': originalEventProperties?.['[Amplitude] Page Title'],
'Demo Page URL': originalEventProperties?.['[Amplitude] Page URL'],
botDetected,
};
return event;
},
};
});

type AmplitudeProps = {
apiKey: string;
Expand All @@ -41,7 +42,7 @@ export const Amplitude: FunctionComponent<AmplitudeProps> = ({ apiKey }) => {
const visitorId = event.products.identification?.data?.visitorId;
const botDetected = event?.products?.botd?.data?.bot?.result === 'bad' ? 'True' : 'False';

amplitude.add(renameEventPropertiesEnrichment);
amplitude.add(demoPageViewedEventPropertiesEnrichment(botDetected));
amplitude.init(apiKey, {
defaultTracking: {
pageViews: {
Expand Down

0 comments on commit 88bcd34

Please sign in to comment.