Skip to content

Instantly share code, notes, and snippets.

@elephantsneverforget
Created April 7, 2024 23:02
Show Gist options
  • Save elephantsneverforget/111d2d4e4dc0e0dfb59e7e40803b6425 to your computer and use it in GitHub Desktop.
Save elephantsneverforget/111d2d4e4dc0e0dfb59e7e40803b6425 to your computer and use it in GitHub Desktop.
export type KlaviyoEventPayload = {
data: {
type: "event";
attributes: {
value?: number;
unique_id: string; // event_id
profile: {
// One of email or phone is required on every API call
$email: string;
$first_name?: string;
$last_name?: string;
$phone_number?: string;
$city?: string;
$region?: string;
$country?: string;
$zip?: string;
$image?: string;
$consent?: string;
country_code?: string;
region_code?: string;
};
metric: {
name: string;
};
properties?: {
// Several properties are sent in duplicate to Klaviyo. The intention is to ensure when a merchant switches to our Klaviyo events, they are still able to use the same naming conventions for product data that they used with their previous events, all while conforming to Klaviyo's recommended naming conventions.
// Top level property items are segmentable in platform so data needs to show twice here
// See bottom of https://help.klaviyo.com/hc/en-us/articles/115005062847
// Legacy top level fields from Elevar's GTM tags for backwards compatibility
ImageURL?: string;
Price?: number;
Name?: string;
ProductName?: string;
ProductID?: string;
URL?: string;
Brand?: string;
CompareAtPrice?: number;
// Suggested fields by Klaviyo for segementation
productTitles?: Array<string>;
variantTitles?: Array<string>;
productIds?: Array<string>;
variantIds?: Array<string>;
prices?: Array<number>;
// skus: Array<string>; // not sending sku since not all products have this and could throw off segments if some have and some don't
categories?: Array<string>;
imageURLs?: Array<string>;
brands?: Array<string>;
lists?: Array<string>;
compareAtPrice?: Array<number>;
items?: Array<KlaviyoItem>;
cartContents?: {
products?: Array<KlaviyoCartItem>;
};
listIds?: Array<string>;
currencies?: Array<string>;
currencySymbols?: Array<string>;
Url?: Array<string | undefined>;
currency_code?: Array<string>;
product_collection_title?: Array<string>;
"Product Title"?: Array<string>;
title?: Array<string>;
Title?: Array<string>;
"Variant Title"?: Array<string>;
"Product Id"?: Array<string>;
"Product ID"?: Array<string>;
ItemId?: Array<string>;
variant_price?: Array<number>;
"Product Price"?: Array<number>;
"Variant Id"?: Array<string>;
skuIds?: Array<string>;
};
};
};
};
type KlaviyoItem = {
variantTitle?: string;
productTitle?: string;
productId?: string;
variantId?: string;
price?: number;
sku?: string;
quantity?: number;
imageUrl?: string;
ImageUrl?: string;
imageURL?: string;
ImageURL?: string;
category?: string;
brand?: string;
productURL?: string;
list?: string;
listId?: string;
currency?: string;
currencySymbol?: string;
compareAtPrice?: number;
url?: string;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment