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

Allow sending visits to a matomo analytics instance #1798

Closed
5 of 9 tasks
acelaya opened this issue Jun 3, 2023 · 1 comment · Fixed by #1920
Closed
5 of 9 tasks

Allow sending visits to a matomo analytics instance #1798

acelaya opened this issue Jun 3, 2023 · 1 comment · Fixed by #1920

Comments

@acelaya
Copy link
Member

acelaya commented Jun 3, 2023

https://github.com/matomo-org/matomo-php-tracker


FAQ:

TODO

  • Visits should be sent using a background job when possible.
  • Make sure there's a reasonable timeout. If the matomo instance goes away, it should not have a big impact on visitors, specially when not using an async runtime.
  • Make dev env more straightforward. Right now you need to go over the installation process and generate some info manually.
  • Document integration with matomo

Nice to have (for future versions):

@acelaya acelaya added this to the 3.7.0 milestone Jun 3, 2023
@acelaya acelaya moved this to Todo in Shlink Jul 31, 2023
@acelaya acelaya moved this from Todo to In Progress in Shlink Nov 8, 2023
@acelaya
Copy link
Member Author

acelaya commented Nov 9, 2023

Send a visit to matomo:

$matomoToken = '...'; // Must be admin/superuser
$matomoSiteId = '3';
$matomoUrl = 'http://shlink_matomo';

// Create a new MatomoTracker on every request, because it infers request info during construction
$tracker = new MatomoTracker($matomoSiteId, $matomoUrl);
$tracker->setTokenAuth($matomoToken);
$tracker->disableBulkTracking(); // We don't want to bulk send, as every request to Shlink will create a new tracker

$tracker
    ->setUrl('http://localhost:8800/foo') // Set absolute short URL for the visit to be tracked
    ->setCity('Zaragoza')
    ->setCountry('Spain')
    ->setRegion('Aragón')
    ->setLatitude(41.656840)
    ->setLongitude(-0.879420)
    ->setIp('1.2.3.4') // Set not obfuscated, as matomo handles obfuscation on itself
    ->setUserAgent('bar')
    ->setRequestMethodNonBulk('POST') // Ensure params are not sent in the URL, for security reasons
    ->setCustomTrackingParameter('type', VisitType::INVALID_SHORT_URL->value)
    ->setCustomTrackingParameter('orphan', 'true') // Set only for orphan visits?
    ->doTrackPageView('http://localhost:8800/foo'); // Use same short URL as action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant