# Klaviyo Web Device Mode Integration

<p>RudderStack lets you send your event data to Klaviyo via <a href="https://www.rudderstack.com/docs/destinations/rudderstack-connection-modes/#device-mode" >device mode</a> using the native web SDK.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">RudderStack loads the Klaviyo native SDK from <code>https://static.klaviyo.com/</code> domain. Based on your website&rsquo;s content security policy, you might need to <a href="https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/load-js-sdk/#allowlist-destination-domain" >allowlist this domain</a> to load the Klaviyo SDK successfully.</div>
  </div>
</blockquote>

</html>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="identify">Identify</h2><p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/identify/" ><code>identify</code></a> call lets you identify a visiting user and associate them to their actions. It also lets you record the traits about them like their name, email address, etc.</p>

<blockquote class="success">
  <div class="tip-quote">
    
    <div class="tip-text">
      You can send any number of key-value pairs as user traits and RudderStack updates them as <a href="https://help.klaviyo.com/hc/en-us/articles/115005074627" >custom profile properties</a> in Klaviyo.
    </div>
  </div>
</blockquote>
<p>To create a new user in Klaviyo, you must pass either the <code>userId</code>, <code>email</code>, or <code>phone</code> properties in the <code>identify</code> call. If a user already exists, RudderStack updates the user profile with the latest values.</p>
<p>A sample <code>identify</code> call is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(&#34;1hKOmRA4el9Z&#34;, {
  firstName: &#34;Alex&#34;,
  lastName: &#34;Keener&#34;,
  email: &#34;alex@example.com&#34;,
  phone: &#34;+12 345 678 900&#34;,
  title: &#34;Owner&#34;,
  organization: &#34;Company&#34;,
  zip: &#34;100-0001&#34;,
  Flagged: false,
  properties: {
    listId: &#34;XUepkK&#34;,
    subscribe: true,
    consent: [&#34;email&#34;],
    smsConsent: true,
  },
})</code></pre></div>
</div>
<p>Note that specifying <code>consent</code> and <code>smsConsent</code> in the event properties overrides the respective settings specified in the <a href="https://www.rudderstack.com/docs/destinations/streaming-destinations/klaviyo/setup-guide/#configuration-settings" >RudderStack dashboard</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="track">Track</h2>
<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">This destination does not strictly adhere to the <a href="https://www.rudderstack.com/docs/event-spec/ecommerce-events-spec/" >RudderStack Ecommerce Event Spec</a>.</div>
  </div>
</blockquote>
<p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/track/" ><code>track</code></a> call lets you record the user actions along with any properties associated with them.</p>
<p>A sample <code>track</code> call is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Checked Out&#34;, {
  Clicked_Rush_delivery_Button: true,
  total_value: 2000,
  Ordered: [&#34;T-Shirt&#34;, &#34;jacket&#34;],
  revenue: 2000,
})</code></pre></div>
</div>
<p>In the above snippet, RudderStack captures the information related to the <code>Checked Out</code> event, along with the details of the event.</p>
<p>To associate a user with an event, you need to pass either their <code>userId</code>, <code>email</code>, or <code>phone</code> in the <code>track</code> call. A sample server-side <code>track</code> call along with the user information is as shown:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">client.track({
  userId: &#34;1hKsmRA4el9Z&#34;,
  event: &#34;Item Purchased&#34;,
  properties: {
    revenue: 97.5,
    products: [
      {
        productId: &#34;pro1&#34;,
        price: 32.5,
        quantity: 3,
      },
    ],
  },
  context: {
    traits: {
      email: &#34;alex@example.com&#34;,
    },
  },
})</code></pre></div>
</div>
<p>In the above snippet, RudderStack captures the information related to the <code>Item Purchased</code> event, along with its additional information in <code>properties</code>. Moreover, since this event is captured using a server-side SDK, RudderStack passes the user information in <code>context</code> along with a unique <code>userId</code>.</p>
<p>Note that:</p>
<ul>
<li>Use <code>context.traits</code> to pass the information in your  <code>track</code> or <code>screen</code> events in case you are using a server-side SDK that does not persist user context information.</li>
<li>To set a specific value to the <code>screen</code> or <code>track</code> type event, you need to pass the event-related property in the <code>properties</code> field. Also, you can send <code>revenue</code> property in the <code>track</code> event and RudderStack will automatically map it to Klaviyo&rsquo;s special property <code>$value</code>.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="ecommerce-event-mapping">Ecommerce event mapping</h3><p>RudderStack converts the following ecommerce events to the corresponding Klaviyo events:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack event</strong></th>
          <th><strong>Klaviyo event</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>Product Viewed</code> <br /> <code>Product Clicked</code></td>
          <td><code>Viewed Product</code></td>
      </tr>
      <tr>
          <td><code>Product Added</code></td>
          <td><code>Added to Cart</code></td>
      </tr>
      <tr>
          <td><code>Checkout Started</code></td>
          <td><code>Started Checkout</code></td>
      </tr>
  </tbody>
</table>
<p>In addition to the above, RudderStack sends the following:</p>
<ul>
<li><strong>Customer properties</strong>: Must contain either the <code>email</code> or <code>phone_number</code>. RudderStack extracts these customer properties from <code>traits</code>/<code>context.traits</code> in the <code>track</code> call.</li>
</ul>
<p>As mentioned above, you can send any number of key-value pairs as user traits and RudderStack updates them as <a href="https://help.klaviyo.com/hc/en-us/articles/115005074627" >custom profile properties</a> in Klaviyo.</p>
<ul>
<li><strong>Token</strong>: Public API key from the RudderStack dashboard.</li>
</ul>
<p>Additionally, you can choose to send specific fields for each of the events covered in the following sections:</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="product-viewed">Product Viewed</h4><p>RudderStack maps the <code>Product Viewed</code> event to <code>Viewed Product</code> and maps the following event properties:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack property</strong></th>
          <th><strong>Klaviyo property</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>name</code></td>
          <td><code>ProductName</code></td>
      </tr>
      <tr>
          <td><code>product_id</code></td>
          <td><code>ProductID</code></td>
      </tr>
      <tr>
          <td><code>sku</code></td>
          <td><code>SKU</code></td>
      </tr>
      <tr>
          <td><code>image_url</code></td>
          <td><code>ImageURL</code></td>
      </tr>
      <tr>
          <td><code>url</code></td>
          <td><code>URL</code></td>
      </tr>
      <tr>
          <td><code>brand</code></td>
          <td><code>Brand</code></td>
      </tr>
      <tr>
          <td><code>price</code></td>
          <td><code>Price</code></td>
      </tr>
      <tr>
          <td><code>compare_at_price</code></td>
          <td><code>CompareAtPrice</code></td>
      </tr>
      <tr>
          <td><code>categories</code></td>
          <td><code>Categories</code></td>
      </tr>
  </tbody>
</table>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="product-added">Product Added</h4><p>RudderStack maps the <code>Product Added</code> event to <code>Added to Cart</code> and maps the following event properties:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack property</strong></th>
          <th><strong>Klaviyo property</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>value</code></td>
          <td><code>$value</code></td>
      </tr>
      <tr>
          <td><code>name</code></td>
          <td><code>AddedItemProductName</code></td>
      </tr>
      <tr>
          <td><code>product_id</code></td>
          <td><code>AddedItemProductID</code></td>
      </tr>
      <tr>
          <td><code>sku</code></td>
          <td><code>AddedItemSKU</code></td>
      </tr>
      <tr>
          <td><code>image_url</code></td>
          <td><code>AddedItemImageURL</code></td>
      </tr>
      <tr>
          <td><code>url</code></td>
          <td><code>AddedItemURL</code></td>
      </tr>
      <tr>
          <td><code>price</code></td>
          <td><code>AddedItemPrice</code></td>
      </tr>
      <tr>
          <td><code>quantity</code></td>
          <td><code>AddedItemQuantity</code></td>
      </tr>
      <tr>
          <td><code>categories</code></td>
          <td><code>AddedItemCategories</code></td>
      </tr>
      <tr>
          <td><code>item_names</code></td>
          <td><code>ItemNames</code></td>
      </tr>
      <tr>
          <td><code>checkout_url</code></td>
          <td><code>CheckoutURL</code></td>
      </tr>
      <tr>
          <td><code>items</code> (deprecating soon) <br/> <code>products</code></td>
          <td><code>Items</code></td>
      </tr>
  </tbody>
</table>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><code>properties.items</code> will be deprecated soon.</div>
  </div>
</blockquote>
<p>Note that <code>products</code>/<code>items</code> can contain the following parameters:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack parameters</strong></th>
          <th><strong>Klaviyo parameters</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>product_id</code></td>
          <td><code>ProductID</code></td>
      </tr>
      <tr>
          <td><code>sku</code></td>
          <td><code>SKU</code></td>
      </tr>
      <tr>
          <td><code>name</code></td>
          <td><code>ProductName</code></td>
      </tr>
      <tr>
          <td><code>quantity</code></td>
          <td><code>Quantity</code></td>
      </tr>
      <tr>
          <td><code>price</code></td>
          <td><code>Price</code></td>
      </tr>
      <tr>
          <td><code>total</code></td>
          <td><code>RowTotal</code></td>
      </tr>
      <tr>
          <td><code>url</code></td>
          <td><code>URL</code></td>
      </tr>
      <tr>
          <td><code>image_url</code></td>
          <td><code>ImageURL</code></td>
      </tr>
      <tr>
          <td><code>categories</code></td>
          <td><code>ProductCategories</code></td>
      </tr>
  </tbody>
</table>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="checkout-started">Checkout Started</h4><p>RudderStack maps the <code>Checkout Started</code> event name to <code>Started Checkout</code> and maps the following event properties:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack Parameters</strong></th>
          <th><strong>Klaviyo Parameters</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>order_id</code></td>
          <td><code>$event_id</code></td>
      </tr>
      <tr>
          <td><code>value</code></td>
          <td><code>$value</code></td>
      </tr>
      <tr>
          <td><code>categories</code></td>
          <td><code>Categories</code></td>
      </tr>
      <tr>
          <td><code>item_names</code></td>
          <td><code>ItemNames</code></td>
      </tr>
      <tr>
          <td><code>items</code> (deprecating soon) <br/> <code>products</code></td>
          <td><code>Items</code></td>
      </tr>
      <tr>
          <td><code>checkout_url</code></td>
          <td><code>CheckoutURL</code></td>
      </tr>
  </tbody>
</table>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><code>properties.items</code> will be deprecated soon.</div>
  </div>
</blockquote>
<p>Note that <code>products</code> / <code>items</code> can contain the following parameters:</p>
<table>
  <thead>
      <tr>
          <th><strong>RudderStack parameters</strong></th>
          <th><strong>Klaviyo parameters</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><code>product_id</code></td>
          <td><code>ProductID</code></td>
      </tr>
      <tr>
          <td><code>sku</code></td>
          <td><code>SKU</code></td>
      </tr>
      <tr>
          <td><code>name</code></td>
          <td><code>ProductName</code></td>
      </tr>
      <tr>
          <td><code>quantity</code></td>
          <td><code>Quantity</code></td>
      </tr>
      <tr>
          <td><code>price</code></td>
          <td><code>Price</code></td>
      </tr>
      <tr>
          <td><code>total</code></td>
          <td><code>RowTotal</code></td>
      </tr>
      <tr>
          <td><code>url</code></td>
          <td><code>URL</code></td>
      </tr>
      <tr>
          <td><code>image_url</code></td>
          <td><code>ImageURL</code></td>
      </tr>
      <tr>
          <td><code>categories</code></td>
          <td><code>ProductCategories</code></td>
      </tr>
  </tbody>
</table>
<p>A sample <code>track</code> call containing the above ecommerce event parameters is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;checkout started &#34;, {
  order_id: &#34;1234&#34;,
  value: 12.34,
  categories: [&#34;category1&#34;, &#34;category2&#34;],
  checkout_url: &#34;http://www.testcall.com&#34;,
  item_names: [&#34;item1&#34;, &#34;item2&#34;],
  products: [{
      product_id: &#34;pId1&#34;,
      sku: &#34;sku1&#34;,
      name: &#34;item1&#34;,
      url: &#34;https://www.item1URL.com&#34;,
      price: 1.0,
      quantity: 1,
      image_url: &#34;https://www.item1Image.com,
      categories: [&#34;category1&#34;, &#34;category2&#34;],
      row_total: 1.0
    },
    {
      product_id: &#34;pId2&#34;,
      sku: &#34;sku2&#34;,
      name: &#34;item2&#34;,
      url: &#34;https://www.item2URL.com&#34;,
      price: 2.0,
      quantity: 1,
      image_url: &#34;https://www.item2Image.com,
      categories: [&#34;category1&#34;, &#34;category2&#34;],
      row_total: 2.0
    },
  ],
});</code></pre></div>
</div>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">It is not mandatory to specify the <code>order_id</code> as Klaviyo automatically assigns the timestamp to the event. However, if explicitly specified, it <strong>must be unique</strong>. Klaviyo automatically discards the events containing a duplicate <code>order_id</code>.</div>
  </div>
</blockquote>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="page">Page</h2><p>The <a href="https://www.rudderstack.com/docs/event-spec/standard-events/page/" ><code>page</code></a> call lets you record your website&rsquo;s page views with any additional relevant information about the viewed page.</p>
<p>You can send the <code>name</code> and <code>category</code> information in the <code>page</code> event by enabling the <strong>Send Page As Track</strong> setting in the RudderStack dashboard. To associate the properties with the page view event, enable the <strong>Additional Page info</strong> setting as well.</p>
<p>A sample <code>page</code> call is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.page(&#34;Cart&#34;, &#34;Cart Viewed&#34;, {
  path: &#34;/cart&#34;,
  referrer: &#34;test.com&#34;,
  search: &#34;term&#34;,
  title: &#34;test_item&#34;,
  url: &#34;http://test.in&#34;,
})</code></pre></div>
</div>

