Interactions
Section titled “Interactions”Interactions are how the Frak SDK records what a user does in your app: arriving from a shared link, sharing a product, or a custom event you define. They are what campaigns and rewards are calculated from.
How Interactions Work
Section titled “How Interactions Work”-
Automatic Tracking: The SDK tracks user arrivals, referrals, and sharing events through a simple fire-and-forget API.
-
Merchant Resolution: The SDK automatically resolves your merchant identity from your domain. No need to pass product or merchant IDs manually.
-
Offline Support: If a user isn’t logged in, interactions are stored locally in the browser and sent once a session is established, ensuring privacy and data integrity.
-
Transparent Process: The entire interaction recording process happens in the background, invisible to the user.
Interaction Types
Section titled “Interaction Types”The SDK supports three interaction types:
arrival: track when a user lands on your site, with optional referral attribution.sharing: track when a user shares your content via the sharing modal.custom: track any custom event specific to your application.
Sending Interactions
Section titled “Sending Interactions”Use the sendInteraction action to record events:
import { import sendInteraction
sendInteraction } from '@frak-labs/core-sdk/actions';
// Track a user arrival with referral attributionawait import sendInteraction
sendInteraction(any
client, { type: string
type: "arrival", referrerWallet: string
referrerWallet: "0x1234...abcd",});
// Track a sharing eventawait import sendInteraction
sendInteraction(any
client, { type: string
type: "sharing" });
// Send a custom interactionawait import sendInteraction
sendInteraction(any
client, { type: string
type: "custom", customType: string
customType: "newsletter_signup", data: { email: string;}
data: { email: string
email: "user@example.com" },});sendInteraction is fire-and-forget: errors are caught and logged, not thrown.
Referral Interactions
Section titled “Referral Interactions”For referral tracking, the SDK provides a dedicated helper that handles the full referral flow automatically:
import { import referralInteraction
referralInteraction } from '@frak-labs/core-sdk/actions';
const const result: any
result = await import referralInteraction
referralInteraction(any
client, { options: { alwaysAppendUrl: boolean; merchantId: string;}
options: { alwaysAppendUrl: boolean
alwaysAppendUrl: true, merchantId: string
merchantId: "550e8400-e29b-41d4-a716-446655440000", },});See referralInteraction for details.
Benefits of Interactions
Section titled “Benefits of Interactions”- Engagement Tracking: Monitor user activity on your platform.
- Reward Systems: Implement campaigns that distribute rewards based on user interactions.
- Privacy-Preserving: Interactions are only sent when a user has an active session.
- Flexible Integration: Use built-in types or define custom interactions for your specific use case.
Best Practices
Section titled “Best Practices”- Use the
referralInteractionhelper for referral flows instead of manually composing arrival interactions. - Set default UTM / attribution params via the SDK
attributionconfig to improve marketing attribution on shared links. - Use
idempotencyKeyon custom interactions to prevent duplicate event recording.
For detailed parameter information, refer to the SendInteractionParamsType reference.