Full Answer
The Klaviyo JavaScript snippet serves two distinct functions. First, it identifies known visitors by matching browser cookies to email addresses collected through Klaviyo forms or WooCommerce checkout. Second, it tracks behavioral events — page views, product views, time on site, and category browsing — that feed Klaviyo's segmentation and predictive models.
Installation is straightforward. Copy the snippet from your Klaviyo account under Settings > Setup > JavaScript snippet. The code block contains your public API key, which is safe to expose client-side. For WordPress sites, the cleanest approach is a lightweight header injection plugin like Insert Headers and Footers by WPCode — paste the snippet in the site-wide header section and save. Alternatively, add it directly to your theme's header.php before the closing tag, though this approach breaks on theme updates unless you use a child theme.
Avoid loading the Klaviyo snippet through Google Tag Manager. GTM fires scripts asynchronously with variable timing, and Klaviyo's identification logic depends on loading before the visitor interacts with the page. GTM-loaded Klaviyo misses early page views and can fail to identify returning visitors whose session starts before the script executes.
After installation, verify using Klaviyo's built-in diagnostics. Navigate to Account > Settings > Setup and check the activity log for incoming events. The dashboard should show page view and active on site events within minutes of installation. If events appear but identified profiles do not, the snippet is working but no identification triggers — forms or checkout events — have fired yet.