Giter Club home page Giter Club logo

traefik-umami-plugin's Introduction

Traefik with Umami traefik-umami-plugin

traefik-umami-plugin

Use Umami Analytics with the Traefik Reverse Proxy.

This plugin enables you to build a middleware to provide umami anytics to any web servive.

Pros:

  • No need to modify the web service
  • Harder to block by adblockers
  • No need for JavaScript Fetching
  • No need for JavaScript

Features

  • Script Tag Injection - Inject the script.js as a script tag
  • Script Source Injection - Inject the script.js as raw JS code
  • Request Forwarding - Forward requests behind forwardingPath to th unami server
  • Server Side Tracking - Trigger tracking event from the plugin, No JS needed.
  • Injection when compressed - Issue, PR in progress

Installation

To add this plugin to traefik reference this repository as a plugin in the static config. The version references a git tag.

experimental:
  plugins:
    traefik-umami-plugin:
      moduleName: "github.com/1cedsoda/traefik-umami-plugin"
      version: "v1.0.2" 
[experimental.plugins.traefik-umami-plugin]
  moduleName = "github.com/1cedsoda/traefik-umami-plugin"
  version = "v1.0.2"

With the plugin installed, you can configure a middleware in a dynamic configuration such as a config.yml or docker labels. Inside traefik-umami-plugin the plugin can be configured.

Only umamiHost and websiteId options are required to get started. The middleware can then be used in a router. Remember to reference the correct provider namespace.

http:
  middlewares:
    my-umami-middleware:
      plugin:
        traefik-umami-plugin:
          umamiHost: "umami:3000"
          websiteId: "d4617504-241c-4797-8eab-5939b367b3ad"
          forwardPath: "umami"
          scriptInjection: true
          scriptInjectionMode: "tag"
          autoTrack: true
          doNotTrack: false
          cache: false
          domains:
            - "example.com"
          evadeGoogleTagManager: false
          serverSideTracking: false
          serverSideTrackingMode: "all"
[http.middlewares]
  [http.middlewares.umami.plugin.traefik-umami-plugin]
    umamiHost = "umami:3000"
    websiteId = "d4617504-241c-4797-8eab-5939b367b3ad"
    forwardPath = "umami"
    scriptInjection = true
    scriptInjectionMode = "tag"
    autoTrack = true
    doNotTrack = false
    cache = false
    domains = ["example.com"]
    evadeGoogleTagManager = false
    serverSideTracking = false

Configuration

Umami Server

key default type description
umamiHost - string Umami server host, reachable from within traefik (container). eg. umami:3000
websiteId - string Website ID as configured in umami.

Request Forwarding

Request forwarding allows for the analytics related requests to be hosted on the same domain as the web service. This makes it harder to block by adblockers. Request forwarding is always enabled.

key default type description
forwardPath umami string Forwards requests with this URL prefix to the umamiHost

Requests with a matching URL are forwarded to the umamiHost. The path is preserved.

  • <forwardPath>/script.js -> <umamiHost>/script.js
  • <forwardPath>/api/send -> <umamiHost>/api/send

Script Injection

If scriptInjection is enabled (by default) and the response Content-Type is text/html, the plugin will inject the Umami script tag/source at the end of the response body.

The data-website-id will be set to the websiteId.

key default type description
scriptInjection true bool Injects the Umami script tag into the response
scriptInjectionMode tag string tag or source. See below
autoTrack true bool See original docs data-auto-track
doNotTrack false bool See original docs data-do-not-track
cache false bool See original docs data-cache
domains [] []string See original docs data-domains
evadeGoogleTagManager false bool See original docs Google Tag Manager

There are two modes for script injection:

  • tag: Injects the script tag with src="/<forwardPath>/script.js" into the response
  • source: Downloads & injects the script source into the response

Server Side Tracking

The plugin can be configured to send tracking events to the Umami server as requests come in. This removes the need for JavaScript on the client side. It also allows to track pages that are not text/html or are not rendered by a browser.

However, it is not possible to track title or display values, as they are not available on the server side.

SST can be combined with script injection, but it is recommended to turn of autoTrack to avoid double tracking.

Tracked events have the name traefik.

The domains configuration is considered for SST as well. If domains is empty, all hosts are tracked, otherwise the host must be in the list. The port of the host is ignored.

key default type description
serverSideTracking false bool Enables server side tracking
serverSideTrackingMode all string all or notinjected. See below

The mode notinjected is useful if you want to use SST and script injection at the same time, but want to avoid double tracking. Perfect for full analytics coverage of your web service. There are two modes for server side tracking:

  • all: Tracks all requests
  • notinjected: Tracks all requests that have not been injected (always if scriptInjection is disabled)

traefik-umami-plugin's People

Contributors

1cedsoda avatar m-s-1-3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

m-s-1-3

traefik-umami-plugin's Issues

Usage

Hi!

I would first like to thank you for taking your time to develop such plugin :)

I would like to have your plugin running for some of my services.

For now, I have a config that looks like this:

      # Umami
      - "traefik.http.middlewares.umami-hauk.plugin.traefik-umami-plugin.umamiHost=umami:3000"
      - "traefik.http.middlewares.umami-hauk.plugin.traefik-umami-plugin.websiteId=3590d714-4221-4075-ac33-88241e5b21fe"
      - "traefik.http.middlewares.umami-hauk.plugin.traefik-umami-plugin.scriptInjectionMode=tag"
      - "traefik.http.middlewares.umami-hauk.plugin.traefik-umami-plugin.ForwardPath=https://umami.mydomain.com"
      # Make usage
      - "traefik.http.routers.hauk.middlewares=ratelimit,secure-headers,authelia,umami-hauk"

https://umami.mydomain.com is the URL to access umami and when I have a new page to be tracked the tracking code script has `src=https://umami.mydomain.com/scripts.js'


When I check traefik logs I see:

g=[traefik-umami-plugin] script: <script async defer data-host-url='/https://umami.mydomain.com' src='/https://umami.mydomain.com/script.js' data-website-id='3590d714-4221-4075-ac33-88241e5b21fe' data-auto-track='true'></script>

It seems that the configuration is incorrect. Could you please guide me on how to configure it properly?

Thanks once again.

[Traefik Plugin Catalog] Plugin Analyzer has detected a problem.

The plugin was not imported into Traefik Plugin Catalog.

Cause:

failed to run the plugin with Yaegi: failed to create a new plugin instance: umami host is not set

Traefik Plugin Analyzer will restart when you will close this issue.

If you believe there is a problem with the Analyzer or this issue is the result of a false positive, please contact us.

Add gzip support

If the response of the service is encoded, the plugin is not able to inject the script, since the </body> regex does not match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.