PiwikPRO.Tracking 1.0.1

dotnet add package PiwikPRO.Tracking --version 1.0.1
                    
NuGet\Install-Package PiwikPRO.Tracking -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PiwikPRO.Tracking" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PiwikPRO.Tracking" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="PiwikPRO.Tracking" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PiwikPRO.Tracking --version 1.0.1
                    
#r "nuget: PiwikPRO.Tracking, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PiwikPRO.Tracking@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PiwikPRO.Tracking&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=PiwikPRO.Tracking&version=1.0.1
                    
Install as a Cake Tool

PiwikPRO.Tracking

Official Piwik PRO .NET SDK for server-side tracking and JavaScript tracking code generation. Send tracking events from your .NET backend and generate client-side tracking snippets for web pages.

Installation

dotnet add package PiwikPRO.Tracking

This automatically installs PiwikPRO.Core with authentication and HTTP infrastructure.

Prerequisites

You need your Piwik PRO instance details:

  1. Your Piwik PRO instance URL (e.g., https://your-instance.piwik.pro)
  2. Your Website/App ID — found under Administration > Sites & Apps
  3. For server-side tracking: an OAuth client (Client ID + Secret) from Menu > Profile > API Keys

Note: JavaScript tracking code generation only requires the instance URL and Website ID — no API credentials needed.

Quick Start

Register Services

using PiwikPRO.Tracking.Extensions;

builder.Services.AddPiwikProTracking(options =>
{
    options.BaseUrl = "https://your-instance.piwik.pro";
    options.ClientId = "your-client-id";
    options.ClientSecret = "your-client-secret";
    options.WebSiteId = "your-website-id";
});

Server-Side Tracking

Track events directly from your server — no client-side JavaScript required:

using PiwikPRO.Tracking;

public class MyService
{
    private readonly ITrackingService _tracking;

    public MyService(ITrackingService tracking) => _tracking = tracking;

    public async Task TrackUserActions()
    {
        // Page view
        await _tracking.TrackPageViewAsync(
            url: "https://example.com/products",
            actionName: "Product Listing Page");

        // Goal conversion with revenue
        await _tracking.TrackGoalAsync(goalId: "abc-123", revenue: 99.99m);

        // File download
        await _tracking.TrackDownloadAsync(
            downloadUrl: "https://example.com/files/whitepaper.pdf");

        // External link click
        await _tracking.TrackOutlinkAsync(linkUrl: "https://external-site.com");

        // Site search
        await _tracking.TrackSiteSearchAsync(
            searchQuery: "product name",
            categories: new List<string> { "Electronics" },
            resultCount: 42);
    }
}

Advanced Tracking with Custom Dimensions

using PiwikPRO.Tracking.Models;

var request = new TrackingRequest
{
    Url = "https://example.com/checkout",
    ActionName = "Checkout - Step 2",
    Uid = "user@example.com",
    CustomDimensions = new Dictionary<string, string>
    {
        ["dimension1"] = "Premium User",
        ["dimension2"] = "US-West"
    },
    EventCustomVars = new Dictionary<string, (string Name, string Value)>
    {
        ["1"] = ("Cart Value", "299.99"),
        ["2"] = ("Items Count", "3")
    }
};

await _tracking.TrackEventAsync(request);

JavaScript Tracking Code Generation

Generate Piwik PRO tracking scripts for embedding in web pages:

using PiwikPRO.Tracking;

// Standard tracking code (uses _paq variable)
var trackingCode = codeGenerator.GenerateTrackingCode();

// Use _ppas variable to avoid conflicts with Matomo
var ppasCode = codeGenerator.GenerateTrackingCode(trackerVariableName: "_ppas");

// Tag Manager + Consent Manager code
var tagManagerCode = codeGenerator.GenerateTagManagerTrackingCode();

// Custom site and account
var customCode = codeGenerator.GenerateTrackingCode(
    siteId: "specific-site-id",
    accountAddress: "custom.containers.piwik.pro");

Example output:


<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//your-instance.piwik.pro/";
    _paq.push(['setTrackerUrl', u+'ppms.php']);
    _paq.push(['setSiteId', 'your-site-id']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'ppms.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

ASP.NET Core Controller Example

public class ScriptController : ControllerBase
{
    private readonly IJavaScriptTrackingCodeGenerator _codeGenerator;

    public ScriptController(IJavaScriptTrackingCodeGenerator codeGenerator)
        => _codeGenerator = codeGenerator;

    [HttpGet("/tracking.js")]
    public IActionResult GetTrackingScript()
    {
        var code = _codeGenerator.GenerateTrackingCode();
        return Content(code, "text/javascript");
    }
}

Configuration Options

Property Type Default Description
BaseUrl string Required Your Piwik PRO instance URL
ClientId string OAuth client ID
ClientSecret string OAuth client secret
AccessToken string? Static access token (alternative to OAuth)
WebSiteId string? Default website ID
TimeoutSeconds int 30 HTTP request timeout
EnableRateLimitHandling bool true Automatic retry on HTTP 429 and 5xx errors
MaxRetryAttempts int 3 Maximum retry attempts

Features

  • Server-Side Tracking — Page views, custom events, goal conversions, downloads, outlinks, site searches
  • Custom Dimensions & Variables — Attach custom data to any tracking event
  • JavaScript Code Generation — Generate standard tracking snippets for web pages
  • Tag Manager Support — Generate Tag Manager + Consent Manager code
  • Tracker Variable Names — Use _ppas instead of _paq to avoid Matomo conflicts
  • Fluent Script BuilderClientSideTrackingScriptBuilder for dynamic tracking scripts
  • ASP.NET Core Integration — Full dependency injection via AddPiwikProTracking()
Package Description
PiwikPRO Meta-package — installs Analytics + Tracking
PiwikPRO.Core Authentication and HTTP infrastructure
PiwikPRO.Analytics Query builder, reporting, sessions, real-time events
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on PiwikPRO.Tracking:

Package Downloads
PiwikPRO

Official Piwik PRO .NET SDK — the complete package. Installs both PiwikPRO.Analytics (fluent query builder, reporting, sessions, real-time events, goals) and PiwikPRO.Tracking (server-side event tracking, JavaScript snippet generation) with all dependencies. The easiest way to integrate Piwik PRO analytics and tracking into your .NET 8 application.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 99 2/26/2026