Alytica Docs
Guides

WordPress

Integrate Alytica with your WordPress website.

Prerequisites

  • An Alytica account
  • Client ID (and optional Client Secret)
  • WordPress website
  • WordPress admin access

Step 1: Install Plugin

  1. Go to WordPress Admin Panel
  2. Navigate to Plugins > Add New
  3. Search for "Header and Footer Scripts"
  4. Install and activate plugins like:
    • "Insert Headers and Footers"
    • "WP Scripts & Styles Optimizer"
    • "Header Footer Code Manager"

Step 2: Add Tracking Script

  1. Go to the plugin's settings
  2. Paste the following in the "Head" section:
<script>
  window.alytica = window.alytica || { q: [] };
  window.alytica.q.push(['init', {
    clientId: 'YOUR_CLIENT_ID',
    trackPageViews: true,
    trackWebVitals: true,
    trackOutgoingLinks: true
  }]);
</script>
<script src="https://app.alytica.tech/script.js" async></script>

Method 2: Edit Theme's functions.php

Step 1: Locate functions.php

  1. Go to Appearance > Theme Editor
  2. Select your active theme's functions.php

Step 2: Add Tracking Script

function add_alytica_tracking() {
    ?>
    <script>
        window.alytica = window.alytica || { q: [] };
        window.alytica.q.push(['init', {
            clientId: 'YOUR_CLIENT_ID',
            trackPageViews: true,
            trackWebVitals: true,
            trackOutgoingLinks: true
        }]);
    </script>
    <script src="https://app.alytica.tech/script.js" async></script>
    <?php
}
add_action('wp_head', 'add_alytica_tracking');

Method 3: Using Google Tag Manager

  1. Install Google Tag Manager plugin
  2. Add Alytica script as a custom HTML tag
  3. Set tag to fire on all pages

Advanced WordPress Tracking

WooCommerce Tracking

Track purchase events:

// Example for tracking purchases
 window.alytica('track', 'purchase', {
  productId: '123',
  productName: 'Premium Theme',
  revenue: 49.99,
  category: 'WordPress Themes'
});

User Registration Tracking

 window.alytica('identify', 'user123', {
  email: 'user@example.com',
  registrationDate: new Date().toISOString(),
  userRole: 'subscriber'
});

Troubleshooting

  • Verify Client ID accuracy
  • Check browser console for errors
  • Ensure script loads on all pages
  • Test tracking in incognito/private browsing mode