Skip to content

Commit

Permalink
fix: Track conversion with GitHub OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Jun 6, 2024
1 parent 07bf9bf commit 786ba7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
15 changes: 1 addition & 14 deletions apps/web/src/views/auth/password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ import {
} from "#lib/utils";
import { useClient } from "#context";

declare global {
interface Window {
gtag?: (
type: string,
event: string,
options: { send_to: string; event_callback: () => void }
) => void;
}
}

const PasswordForm: AuthFormComponent = (props) => {
const client = useClient();
const [hidePassword, setHidePassword] = createSignal(true);
Expand Down Expand Up @@ -68,10 +58,7 @@ const PasswordForm: AuthFormComponent = (props) => {
redirect: props.redirect,
plan: props.plan
});
window.gtag?.("event", "conversion", {
send_to: "AW-16595937003/5SD4CLf_vLcZEOvNx-k9",
event_callback: () => {}
});
props.onRegister?.();
setLoading(false);
props.setFormData("formType", "verify-email");
} catch (error) {
Expand Down
21 changes: 21 additions & 0 deletions apps/web/src/views/auth/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,21 @@ interface AuthFormComponentProps {
redirect?: string;
plan?: string;
setFormData: SetStoreFunction<AuthFormData>;
onRegister?: () => void;
}

type AuthFormComponent = Component<AuthFormComponentProps>;

declare global {
interface Window {
gtag?: (
type: string,
event: string,
options: { send_to: string; event_callback: () => void }
) => void;
}
}

const AuthView: Component = () => {
const hostConfig = useHostConfig();
const client = useClient();
Expand Down Expand Up @@ -71,8 +82,15 @@ const AuthView: Component = () => {
setShowForm(true);
}
};
const trackConversion = (): void => {
window.gtag?.("event", "conversion", {
send_to: "AW-16595937003/5SD4CLf_vLcZEOvNx-k9",
event_callback: () => {}
});
};
const continueWithGitHub = (): void => {
setFormData("loading", true);
trackConversion();
window.location.replace(`/login/github?plan=${plan}`);
};

Expand Down Expand Up @@ -121,6 +139,9 @@ const AuthView: Component = () => {
setFormData={setFormData}
redirect={redirect}
plan={plan}
onRegister={() => {
trackConversion();
}}
footer={
<>
<Show when={hostConfig.githubOAuth}>
Expand Down

0 comments on commit 786ba7c

Please sign in to comment.