Skip to content

CodeArtDK/CodeArt.MatomoTracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuget

CodeArt.MatomoTracking

Opensource Matomo Tracking API for .NET. This library is based on the official Matomo Tracking API documentation: https://developer.matomo.org/api-reference/tracking-api and wraps the API calls in a simple to use .NET library. Initial version made by Allan Thraen for CodeArt.

Installation

Register the Matomo Tracking as a service in Dependency Injection.

        var services = new ServiceCollection();
        
        //Needs IConfiguration - but this might already be registered in your project
        services.AddScoped<IConfiguration>(_ => configuration);
		
        services.AddMatomoTracking(options =>
        {
            options.MatomoUrl = "https://[My matomo hostname]/";
            options.SiteId = "[My site id]";
            options.AuthToken ="[My auth token]"; //Optional
            options.TrackBots = true; //Optional
            options.VerboseLogging = true; //Optional - logs the URLs tracked.
        });
        var serviceProvider = services.BuildServiceProvider();

Configuration

If you have a configuration file, you can also set the configuration directly there under the "Matomo" node.

{
  "Matomo": {
	"MatomoHostname": "[My matomo hostname]",
	"SiteId": "[My site id]"
  }
}

Usage

You can track many different things, for example:

  • Pageviews using PageViewTrackingItems
  • Events using EventTrackingItems
  • Ecommerce using EcommerceTrackingItems
  • Content using ContentTrackingItems

For the official documentation of what to track - and when, refer to the (official documentation)[https://developer.matomo.org/api-reference/tracking-api]

Tracking a page view

    await tracker.Track(new PageViewTrackingItem()
    {
        Url = "app://myapp/page1",
        UserID = "test@test.com",
        NewVisit = true,
        ActionName = "Page 1",
        PageViewID = pvid
    });

Tracking in bulk

You can also track multiple items in the same call like this:

    await tracker.Track(new PageViewTrackingItem()
    {
        Url = "app://myapp/page1",
        UserID = "test@test.com",
        NewVisit = true,
        ActionName = "Page 1",
        PageViewID = pvid
    },
    new EventTrackingItem()
    {
        Url = "app://myapp/page1",
        UserID = "test", 
        NewVisit = false,
        ActionName = "Form submit",
        PageViewID = pvid,
        EventCategory = "Form",
        EventAction = "Submit",
        EventName = "Newsletter form"
    });

About

Opensource Matomo Tracking API for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published