Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send custom GA event when new app is created #1285

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/toolpad-app/src/toolpad/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { ConfirmDialog } from '../../components/SystemDialogs';
import config from '../../config';
import { AppTemplateId } from '../../types';
import { errorFrom } from '../../utils/errors';
import { sendAppCreatedEvent } from '../../utils/ga';

export const APP_TEMPLATE_OPTIONS: Map<
AppTemplateId,
Expand Down Expand Up @@ -154,6 +155,8 @@ function CreateAppDialog({ onClose, ...props }: CreateAppDialogProps) {
recaptchaToken,
},
]);

sendAppCreatedEvent(name, appTemplateId);
}}
>
<DialogTitle>Create a new MUI Toolpad App</DialogTitle>
Expand Down
10 changes: 10 additions & 0 deletions packages/toolpad-app/src/utils/ga.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NextWebVitalsMetric } from 'next/app';
import config from '../config';
import { AppTemplateId } from '../types';

export const setGAPage = (pagePath: string): void => {
if (config.gaId) {
Expand All @@ -17,3 +18,12 @@ export const reportWebVitalsToGA = ({ id, label, name, value }: NextWebVitalsMet
});
}
};

export const sendAppCreatedEvent = (name: string, templateId?: AppTemplateId): void => {
if (config.gaId) {
window.gtag('event', 'app_created', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to namespace those toolpad_app_created?

Copy link
Member Author

@apedroferreira apedroferreira Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not, would be a good standard for custom events, will add

app_name: name,
app_template_id: templateId,
});
}
};