Klaviyo Lookup Variable for GTM Server Side

This Google Tag Manager Server-Side variable allows you to retrieve a user profile from Klaviyo using the identifier (_kx). It enriches your server-side data with user information such as email, phone number, and address.

How it works

  1. Known Email Shortcut (optional): If Output is set to Email, Skip API call for known email is checked, and the provided Email Address is a valid email, the variable returns that email (trimmed and lowercased) right away. It skips the identifier lookup, the cache and the API call. Otherwise, it continues with the steps below.
  2. Identifier Detection: The variable first looks for the _kx query parameter in the page URL.
  3. Fallback: If the URL parameter is not present, it attempts to retrieve the identifier from the stape_klaviyo_kx cookie.
  4. Second Fallback: If neither is present, it reads the __kla_id cookie set by Klaviyo’s onsite JS, decodes it, and uses its $exchange_id as the identifier.
  5. Cache Check: The variable checks the templateDataStorage to see if the user data for this identifier is already cached, preventing unnecessary API calls.
  6. API Request: If no cache is found, it sends a GET request to the Klaviyo Profiles API.
  7. Output: It returns either the user’s email or a full user data object based on your configuration.

Parameters

  • Private API Key: Input your Klaviyo Private API Key. This is required to authorize the request. Learn more.
  • Output: Select the type of data to return:
    • Email: Returns only the user’s email address string.
    • All User Data: Returns a JSON object containing the user profile.
  • Skip API call for known email (only available when Output is Email): Check this box to provide an email you already know, such as an Event Data variable mapped to the user’s email, and avoid the Klaviyo API call.
    • Email Address: The email to return. It is trimmed and lowercased before it is returned, to match the format of emails fetched from Klaviyo. If the value isn’t a string or doesn’t look like a valid email address, the variable ignores it and falls back to the regular Klaviyo lookup.

Returned Data Structure

If All User Data is selected, the variable returns an object containing the following attributes:

{
  "email": "user@example.com",
  "phone_number": "+1234567890",
  "address": [
    {
      "first_name": "john",
      "last_name": "doe",
      "street": "123 main st",
      "city": "new york",
      "postal_code": "10001",
      "country": "us"
    }
  ]
}

Open Source

Initial development was done by Lars Friis.

Klaviyo Lookup Variable for GTM Server Side is developed and maintained by Stape Team under the Apache 2.0 license.

GTM Gallery Status

:green_circle: Listed

GitHub

:green_circle: Repository

stape-io/klaviyo-lookup-variable — updated: view commit

  • Removed Logs Settings group and related logging functionality from the template
  • Updated API revision date to 2026-04-15
  • Simplified and optimized helper functions, removing logging-related conditionals
  • Cleaned up dependencies, removing unused logging modules and rearranging imports
  • Removed configuration sections related to logging and header access permissions

GTM Gallery Status

:green_circle: Listed

1 Like

stape-io/klaviyo-lookup-variable — updated: view commit

  • Renamed “Api Key” to “Private API Key” and added setup documentation
  • Expanded Klaviyo Exchange ID detection to include the __kla_id cookie
  • Added cached profile lookups with email or full user data output
  • Updated the Klaviyo API revision to 2026-07-15

GTM Gallery Status

:green_circle: Listed

stape-io/klaviyo-lookup-variable — updated: view commit

  • Added an option to provide a known email address and skip the API call
  • Valid email inputs are normalized and returned directly; invalid inputs continue through the standard API lookup

GTM Gallery Status

:green_circle: Listed