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)
|
# DataFast Analytics (https://datafa.st)
|
||||||
# https://mksaas.com/docs/analytics#datafast
|
# https://mksaas.com/docs/analytics#datafast
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
NEXT_PUBLIC_DATAFAST_ANALYTICS_ID=""
|
NEXT_PUBLIC_DATAFAST_WEBSITE_ID=""
|
||||||
NEXT_PUBLIC_DATAFAST_ANALYTICS_DOMAIN=""
|
NEXT_PUBLIC_DATAFAST_DOMAIN=""
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
import { findPlanByPlanId } from '@/lib/price-plan';
|
import { findPlanByPlanId } from '@/lib/price-plan';
|
||||||
import { getSession } from '@/lib/server';
|
import { getSession } from '@/lib/server';
|
||||||
import { getUrlWithLocale } from '@/lib/urls/urls';
|
import { getUrlWithLocale } from '@/lib/urls/urls';
|
||||||
@ -8,6 +9,7 @@ import type { CreateCheckoutParams } from '@/payment/types';
|
|||||||
import { Routes } from '@/routes';
|
import { Routes } from '@/routes';
|
||||||
import { getLocale } from 'next-intl/server';
|
import { getLocale } from 'next-intl/server';
|
||||||
import { createSafeActionClient } from 'next-safe-action';
|
import { createSafeActionClient } from 'next-safe-action';
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
// Create a safe action client
|
// 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
|
// Add user id to metadata, so we can get it in the webhook event
|
||||||
const customMetadata = {
|
const customMetadata: Record<string, string> = {
|
||||||
...metadata,
|
...metadata,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
userName: session.user.name,
|
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
|
// Create the checkout session with localized URLs
|
||||||
const successUrl = getUrlWithLocale(
|
const successUrl = getUrlWithLocale(
|
||||||
'/settings/billing?session_id={CHECKOUT_SESSION_ID}',
|
'/settings/billing?session_id={CHECKOUT_SESSION_ID}',
|
||||||
|
@ -37,6 +37,7 @@ export const websiteConfig: WebsiteConfig = {
|
|||||||
enableUpgradeCard: true,
|
enableUpgradeCard: true,
|
||||||
enableAffonsoAffiliate: false,
|
enableAffonsoAffiliate: false,
|
||||||
enablePromotekitAffiliate: false,
|
enablePromotekitAffiliate: false,
|
||||||
|
enableDatafastRevenueTrack: false,
|
||||||
},
|
},
|
||||||
routes: {
|
routes: {
|
||||||
defaultLoginRedirect: '/dashboard',
|
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
|
enableUpgradeCard?: boolean; // Whether to enable the upgrade card in the sidebar
|
||||||
enableAffonsoAffiliate?: boolean; // Whether to enable affonso affiliate
|
enableAffonsoAffiliate?: boolean; // Whether to enable affonso affiliate
|
||||||
enablePromotekitAffiliate?: boolean; // Whether to enable promotekit affiliate
|
enablePromotekitAffiliate?: boolean; // Whether to enable promotekit affiliate
|
||||||
|
enableDatafastRevenueTrack?: boolean; // Whether to enable datafast revenue tracking
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user