Skip to content
Snippets Groups Projects

Matomo KSS plugin

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Thimo Kraemer
    Edited
    kss-matomo.js 1.17 KiB
    /*******************************************************************************************
     * KSS Matomo Plugin
     ******************************************************************************************/
    
    var _paq = window._paq || [];
    _paq.push([function() {
        kss.matomo = this;
    }]);
    
    kss.registerActionProvider('matomoPush', function(node, params) {
        var data = [params.func];
        var args = params.args;
        if (args) {
            if (typeof args == 'string') {
                args = args.split(/\s+/);
            }
            data = data.concat(args);
        }
        _paq.push(data);
    });
    
    kss.registerActionProvider('matomoCall', function(node, params) {
        var args = params.args;
        if (typeof args == 'string') {
            args = args.split(/\s+/);
        }
        if (!kss.matomo) {
            throw new Error('Matomo not (yet?) loaded');
        }
        kss.matomo[params.func].apply(kss.matomo, args);
    });
    
    kss.registerParameterProvider('matomoCall', function(node, func, args) {
        if (!kss.matomo) {
            throw new Error('Matomo not (yet?) loaded');
        }
        return kss.matomo[func].apply(kss.matomo, args);
    });
    
    kss.registerParameterProvider('matomoIsLoaded', function(node) {
        return !!kss.matomo;
    });
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment