Skip to main content
Add PostMetric to your WordPress site in minutes.

Installation

  1. Install a “Insert Headers and Footers” plugin
  2. Go to SettingsInsert Headers and Footers
  3. Add the tracking script to the Header section:
<script src="https://your-domain.com/api/track.js?site=YOUR_TRACKING_CODE"></script>
Replace YOUR_TRACKING_CODE with your tracking code from the dashboard.

Method 2: Edit theme files

  1. Go to AppearanceTheme Editor
  2. Select header.php
  3. Add the tracking script before the closing </head> tag:
<script src="https://your-domain.com/api/track.js?site=YOUR_TRACKING_CODE"></script>
Editing theme files directly will lose changes when the theme updates. Use a child theme or plugin method instead.

Track custom goals

Track custom goals in your WordPress posts/pages:
<button onclick="postMetric('track', 'goal', { event: 'button_click' })">
  Click me
</button>
Or in your theme’s JavaScript:
document.getElementById("my-button").addEventListener("click", function () {
  postMetric("track", "goal", { event: "button_click" });
});

WooCommerce integration

Track purchases in WooCommerce:
add_action('woocommerce_thankyou', 'track_purchase');
function track_purchase($order_id) {
    $order = wc_get_order($order_id);
    ?>
    <script>
    postMetric('track', 'goal', {
        event: 'purchase',
        value: <?php echo $order->get_total(); ?>
    });
    </script>
    <?php
}

Next steps

Track custom goals

Learn how to track custom user actions