Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook into Hit-Tracking #1099

Open
djstini opened this issue Apr 18, 2024 · 5 comments
Open

Hook into Hit-Tracking #1099

djstini opened this issue Apr 18, 2024 · 5 comments
Labels
Enhancement For new feature suggestions that for example enhance Matomo's cabapilities..

Comments

@djstini
Copy link

djstini commented Apr 18, 2024

Hi,

is there a way to trigger a custom action on every visit that is filtered/tracked by Matomo?

Couldn't find anything on that in the Documentation https://developer.matomo.org/api-reference/wordpress/hooks-reference#filters

@diosmosis diosmosis added the Enhancement For new feature suggestions that for example enhance Matomo's cabapilities.. label Apr 18, 2024
@diosmosis
Copy link
Member

Hi @djstini, there's currently no WordPress specific hook, though it shouldn't be too hard to add. Can you explain your intended use case? What would you use such a hook for?

@djstini
Copy link
Author

djstini commented Apr 18, 2024

Hi @diosmosis my Use-Case is the following:

We are using Matomo for the general tracking of the site. As Matomo includes mechanisms to filter out bots etc. i would like to leverage this filtering in order to create, for example, custom metrics.

Let's say for example whenever a "real" visitor visits a page I want to update a post-meta.

@diosmosis
Copy link
Member

diosmosis commented Apr 18, 2024

@djstini for something that generic, it sounds like you might be better served by creating a custom Matomo plugin, and having that installed in WordPress. Is that a solution that might work for you? (Note: you would want to look at the RequestProcessor API, https://developer.matomo.org/guides/tracking-requests. You'd create a new one in a new Matomo plugin, and add your WordPress specific logic to one of the hooks in that class.)

@djstini
Copy link
Author

djstini commented Apr 18, 2024

Ahh okay, so i'd just extend on the Matomo-RequestProcessor and add my stuff that way. That sounds doable.

Thanks :3

@diosmosis
Copy link
Member

diosmosis commented Apr 18, 2024

Glad this approach might work for you! One thing to note: for Matomo plugins to be installed as WordPress plugins, the main plugin file needs to have this bit of code at the top:

if (defined( 'ABSPATH')
&& function_exists('add_action')) {
    $path = '/matomo/app/core/Plugin.php';
    if (defined('WP_PLUGIN_DIR') && WP_PLUGIN_DIR && file_exists(WP_PLUGIN_DIR . $path)) {
        require_once WP_PLUGIN_DIR . $path;
    } elseif (defined('WPMU_PLUGIN_DIR') && WPMU_PLUGIN_DIR && file_exists(WPMU_PLUGIN_DIR . $path)) {
        require_once WPMU_PLUGIN_DIR . $path;
    } else {
        return;
    }
    add_action('plugins_loaded', function () {
        if (function_exists('matomo_add_plugin')) {
            matomo_add_plugin(__DIR__, __FILE__, true);
        }
    });
}

This isn't documented anywhere as far as I know, since it's automatically added by Matomo marketplace. You'll have to add it yourself.

I'll keep this issue open as I imagine WordPress hooks would be more convenient for some use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that for example enhance Matomo's cabapilities..
Projects
None yet
Development

No branches or pull requests

2 participants