Install guides / Website builders & CMS

Add PageLens analytics to WooCommerce

PageLens is cookieless website analytics: no consent banner, a ~3 KB script, real-time stats, funnels, session replay and AI-traffic insights. Setup on WooCommerce takes about two minutes.

Steps

  1. Add the snippet to WordPress as described in the WordPress guide (WPCode → Header & Footer → Header).
  2. To track purchases with their value, add the code below to your child theme's functions.php.
  3. Create a goal for the purchase event in PageLens to see your conversion rate.
<script defer src="https://app.pagelens.io/script.js" data-site-id="YOUR_SITE_ID"></script>

Replace YOUR_SITE_ID with the id from your site settings in PageLens. The dashboard shows the exact snippet with your id filled in.

Track purchases

add_action('woocommerce_thankyou', function ($order_id) {
  $order = wc_get_order($order_id);
  if (!$order) return;
  printf(
    "<script>addEventListener('load',function(){window.pagelens&&pagelens.track('purchase',{value:%s,currency:'%s'})})</script>",
    json_encode((float) $order->get_total()),
    esc_js($order->get_currency())
  );
});

Check that it works

Open your site in a new tab, then open PageLens. The live counter shows your visit within a few seconds. Visits from localhost are ignored by default.

Track custom events

Add data-pagelens-event to any button or form, or call the JavaScript API:

<button data-pagelens-event="signup" data-pagelens-prop-plan="pro">Start trial</button>

<script>
  window.pagelens?.track('signup', { plan: 'pro' })
</script>

You can also turn on autocapture for button clicks, form submissions and copy events in Site Settings → Tracking. No code is needed.

Avoid ad blockers

Some ad blockers drop requests to analytics domains. Serve PageLens from your own domain to count those visits too.

Don't have a site ID yet?

Create a free PageLens account: 7-day trial, no card, no cookie banner needed.

Start free trial

Other website builders & cms

WordPressShopifyWebflowFramerWixSquarespaceGhostHubSpot CMS