Comprehensive Guide to Matomo Node.js Tracker for Effective Analytics Integration

Introduction to Matomo Node.js Tracker

Matomo, formerly known as Piwik, is a highly customizable and open-source web analytics platform. With the matomo-nodejs-tracker package, integrating Matomo into your Node.js application has never been easier. This guide will introduce you to the matomo-nodejs-tracker and provide dozens of useful API examples to help you get started.

Getting Started


const MatomoTracker = require('matomo-nodejs-tracker');
const matomo = new MatomoTracker(1, 'http://your-matomo-url/matomo.php');

Tracking Page Views


matomo.track({
   url: 'http://example.com',
   action_name: 'HomePage'
});

Tracking Events


matomo.track({
   url: 'http://example.com',
   e_c: 'Video',
   e_a: 'Play',
   e_n: 'Fall Campaign'
});

Tracking Goals


matomo.track({
   url: 'http://example.com',
   idgoal: 1,
   rand: 0.5
});

Custom Variable Tracking


matomo.track({
   url: 'http://example.com',
   '_cvar': JSON.stringify({ '1': ['UserType', 'Member'] })
});

Tracking Ecommerce Orders


matomo.track({
   url: 'http://example.com/order-confirmation',
   ecommerce: JSON.stringify({
     id: 1,
     grandTotal: 50,
     items: [{ sku: 'LTV-257', name: 'T-Shirt', category: 'Apparel', price: 50, quantity: 1 }]
   })
});

Tracking Site Search


matomo.track({
   url: 'http://example.com/search',
   search: 'T-Shirt',
   search_cat: 'Apparel',
   search_count: 100
});

App Example with All Introduced APIs


const express = require('express');
const MatomoTracker = require('matomo-nodejs-tracker');
const app = express();
const matomo = new MatomoTracker(1, 'http://your-matomo-url/matomo.php');

app.get('/', (req, res) => {
  matomo.track({
    url: req.protocol + '://' + req.get('host') + req.originalUrl,
    action_name: 'HomePage'
  });
  res.send('Welcome to Home Page');
});

app.get('/play', (req, res) => {
  matomo.track({
    url: req.protocol + '://' + req.get('host') + req.originalUrl,
    e_c: 'Video',
    e_a: 'Play',
    e_n: 'Fall Campaign'
  });
  res.send('Playing Fall Campaign Video');
});

app.get('/order', (req, res) => {
  matomo.track({
    url: req.protocol + '://' + req.get('host') + req.originalUrl,
    ecommerce: JSON.stringify({
      id: 1,
      grandTotal: 50,
      items: [{ sku: 'LTV-257', name: 'T-Shirt', category: 'Apparel', price: 50, quantity: 1 }]
    })
  });
  res.send('Order Confirmed');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

And that concludes our guide to using the matomo-nodejs-tracker in your Node.js applications. Integrating Matomo enables you to effectively track user interactions and make data-driven decisions. Happy coding!

Hash: ccaa023001d6602a7713284553a1bd30041814dd4eec6941b2114dbb89ce8430

Leave a Reply

Your email address will not be published. Required fields are marked *