Skip to content

Commit

Permalink
🪟 Add Segment event for 'Buy Credits' (#15366)
Browse files Browse the repository at this point in the history
* add segment event for "Buy credits" button

* update event's name for checkout process
  • Loading branch information
dizel852 authored Aug 8, 2022
1 parent c39a7c4 commit 546c24a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions airbyte-webapp/src/core/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const enum Namespace {
CONNECTOR = "Connector",
ONBOARDING = "Onboarding",
USER = "User",
CREDITS = "Credits",
}

export const enum Action {
Expand All @@ -34,6 +35,7 @@ export const enum Action {
PREFERENCES = "Preferences",
NO_MATCHING_CONNECTOR = "NoMatchingConnector",
SELECTION_OPENED = "SelectionOpened",
CHECKOUT_START = "CheckoutStart",
}

export type EventParams = Record<string, unknown>;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import styled from "styled-components";
import { Button, LoadingButton } from "components";

import { useConfig } from "config";
import { Action, Namespace } from "core/analytics";
import { useAnalyticsService } from "hooks/services/Analytics";
import { useCurrentWorkspace } from "hooks/services/useWorkspace";
import { CloudWorkspace } from "packages/cloud/lib/domain/cloudWorkspaces/types";
import { useStripeCheckout } from "packages/cloud/services/stripe/StripeService";
Expand Down Expand Up @@ -67,6 +69,7 @@ const RemainingCredits: React.FC<Props> = ({ selfServiceCheckoutEnabled }) => {
const [searchParams, setSearchParams] = useSearchParams();
const invalidateWorkspace = useInvalidateCloudWorkspace(currentWorkspace.workspaceId);
const { isLoading, mutateAsync: createCheckout } = useStripeCheckout();
const analytics = useAnalyticsService();
const [isWaitingForCredits, setIsWaitingForCredits] = useState(false);

useEffectOnce(() => {
Expand Down Expand Up @@ -107,6 +110,9 @@ const RemainingCredits: React.FC<Props> = ({ selfServiceCheckoutEnabled }) => {
successUrl: successUrl.href,
cancelUrl: window.location.href,
});
await analytics.track(Namespace.CREDITS, Action.CHECKOUT_START, {
actionDescription: "Checkout Start",
});
// Forward to stripe as soon as we created a checkout session successfully
window.location.assign(stripeUrl);
};
Expand Down

0 comments on commit 546c24a

Please sign in to comment.