Refer a Friend Premium for WooCommerce includes a built-in Klaviyo integration that automatically syncs referral codes to customer profiles and fires a Referral Code Created event whenever a new code is generated. This lets you build personalised email flows in Klaviyo that reference each customer’s unique referral code or trigger immediately after a code is created.
This guide covers the Klaviyo private API key permissions you need, how to set up the integration in the plugin, and what data is sent to Klaviyo.
Required Klaviyo API Key Permissions
The integration uses two Klaviyo API endpoints, so your private API key must have the following scopes enabled when you create it:
| Scope | Access Level | Used For |
|---|---|---|
| Profiles | Read and Write | Creating or updating the customer profile and storing the referral code as a custom property. |
| Events | Write | Firing the Referral Code Created event whenever a new referral code is generated. |
If you want to keep the API key minimal for security, only enable these two scopes. A full-access key also works.
Step 1: Create the Klaviyo Private API Key
- Log in to your Klaviyo account.
- Go to Account → Settings → API Keys.
- Click Create Private API Key.
- Give the key a descriptive name, for example Refer a Friend Plugin.
- Choose Custom Key to set granular scopes.
- Enable Profiles → Read and Write and Events → Write.
- Click Create and copy the key. You will not be able to see it again after closing the dialog.
Step 2: Enable the Integration in the Plugin
- In your WordPress admin, go to Refer a Friend → Integrations.
- Find the Klaviyo section.
- Toggle Enabled to on.
- Paste your private API key into the API Key field.
- Click Save.
The integration is now active. From this point on, every newly generated referral code will be sent to Klaviyo automatically.
What Data Is Sent to Klaviyo
Profile Properties
When a referral code is created, the plugin upserts the customer profile in Klaviyo with the following fields:
| Field | Type | Description |
|---|---|---|
email | String | Customer’s email address. Used as the unique profile identifier. |
first_name | String | Customer’s first name. Only sent when available. |
last_name | String | Customer’s last name. Only sent when available. |
referral_code | String (custom property) | The customer’s unique referral code. Use this in email templates as {{ person.referral_code }}. |
referral_created_date | ISO 8601 datetime (custom property) | Timestamp when the referral code was created. |
Event: Referral Code Created
Immediately after the profile is updated, the plugin fires a Referral Code Created metric event. Use this event as the trigger for a Klaviyo flow that sends the referral code to the customer.
| Property | Type | Description |
|---|---|---|
referral_code | String | The newly created referral code. |
user_type | String | Either registered_user (the customer has a WordPress account) or guest_user (generated from a guest checkout or signup form). |
created_at | ISO 8601 datetime | Timestamp when the code was created. |
unique_id | String (SHA-256 hash) | Deterministic ID derived from email, code, user type, and timestamp. Prevents duplicate events if the request is retried. |
Building a Welcome Flow in Klaviyo
- In Klaviyo, go to Flows → Create Flow → Create From Scratch.
- Set the trigger to Metric → Referral Code Created.
- Add an Email step.
- In the email body, insert the placeholder
{{ person.referral_code }}wherever you want the referral code to appear. You can also use{{ event.referral_code }}to pull the code directly from the triggering event. - Optionally add a Trigger Split filtering on
user_type = registered_userif you want different copy for guest signups. - Activate the flow.
Migrating From the Old Code Snippet
Earlier versions of this guide showed a custom snippet that hooked into wpgens_raf_new_user_referral_id and called the Klaviyo API directly from functions.php. That snippet is no longer needed. The built-in integration covers the same use case, plus it adds the Referral Code Created event for flow triggers and supports both registered and guest users.
If you have the legacy snippet in your theme’s functions.php or in a custom site plugin, remove it before enabling the built-in integration to avoid sending each referral code twice.