chore: support datafast analytics revenue track
This commit is contained in:
parent
bc915a53dc
commit
b3180e617d
@ -119,8 +119,8 @@ NEXT_PUBLIC_SELINE_TOKEN=""
|
||||
# DataFast Analytics (https://datafa.st)
|
||||
# https://mksaas.com/docs/analytics#datafast
|
||||
# -----------------------------------------------------------------------------
|
||||
NEXT_PUBLIC_DATAFAST_ANALYTICS_ID=""
|
||||
NEXT_PUBLIC_DATAFAST_ANALYTICS_DOMAIN=""
|
||||
NEXT_PUBLIC_DATAFAST_WEBSITE_ID=""
|
||||
NEXT_PUBLIC_DATAFAST_DOMAIN=""
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { websiteConfig } from '@/config/website';
|
||||
import { findPlanByPlanId } from '@/lib/price-plan';
|
||||
import { getSession } from '@/lib/server';
|
||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||
@ -8,6 +9,7 @@ import type { CreateCheckoutParams } from '@/payment/types';
|
||||
import { Routes } from '@/routes';
|
||||
import { getLocale } from 'next-intl/server';
|
||||
import { createSafeActionClient } from 'next-safe-action';
|
||||
import { cookies } from 'next/headers';
|
||||
import { z } from 'zod';
|
||||
|
||||
// Create a safe action client
|
||||
@ -67,12 +69,22 @@ export const createCheckoutAction = actionClient
|
||||
}
|
||||
|
||||
// Add user id to metadata, so we can get it in the webhook event
|
||||
const customMetadata = {
|
||||
const customMetadata: Record<string, string> = {
|
||||
...metadata,
|
||||
userId: session.user.id,
|
||||
userName: session.user.name,
|
||||
};
|
||||
|
||||
// https://datafa.st/docs/stripe-checkout-api
|
||||
// if datafast analytics is enabled, add the revenue attribution to the metadata
|
||||
if (websiteConfig.features.enableDatafastRevenueTrack) {
|
||||
const cookieStore = await cookies();
|
||||
customMetadata.datafast_visitor_id =
|
||||
cookieStore.get('datafast_visitor_id')?.value ?? '';
|
||||
customMetadata.datafast_session_id =
|
||||
cookieStore.get('datafast_session_id')?.value ?? '';
|
||||
}
|
||||
|
||||
// Create the checkout session with localized URLs
|
||||
const successUrl = getUrlWithLocale(
|
||||
'/settings/billing?session_id={CHECKOUT_SESSION_ID}',
|
||||
|
@ -37,6 +37,7 @@ export const websiteConfig: WebsiteConfig = {
|
||||
enableUpgradeCard: true,
|
||||
enableAffonsoAffiliate: false,
|
||||
enablePromotekitAffiliate: false,
|
||||
enableDatafastRevenueTrack: false,
|
||||
},
|
||||
routes: {
|
||||
defaultLoginRedirect: '/dashboard',
|
||||
|
1
src/types/index.d.ts
vendored
1
src/types/index.d.ts
vendored
@ -70,6 +70,7 @@ export interface FeaturesConfig {
|
||||
enableUpgradeCard?: boolean; // Whether to enable the upgrade card in the sidebar
|
||||
enableAffonsoAffiliate?: boolean; // Whether to enable affonso affiliate
|
||||
enablePromotekitAffiliate?: boolean; // Whether to enable promotekit affiliate
|
||||
enableDatafastRevenueTrack?: boolean; // Whether to enable datafast revenue tracking
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user