partytown icon indicating copy to clipboard operation
partytown copied to clipboard

How can I integrate matomo analytics?

Open rrolla opened this issue 3 years ago • 9 comments

Is your feature request related to a problem? Please describe. I want to use this fantastic idea to offload main thread for matomo analytics

Describe the solution you'd like Help to understand how can I integrate it with code examples, and update forwarding events documentation with advanced cases

Describe alternatives you've considered Point to some similar integration

Additional context JavaScript Tracking Client for matomo https://developer.matomo.org/guides/tracking-javascript-guide

I added scripts


<script>
  partytown = {
    debug: true,
    forward: ["_paq.push"],
    lib: "/~partytown/",
    logCalls: true,
    logGetters: true,
    logSetters: true,
    logImageRequests: true,
    logMainAccess: true,
    logScriptExecution: true,
    logSendBeaconRequests: true,
    logStackTraces: true
  };
</script>

<script>
  window._paq = [];
  _paq.push(["trackPageView"]);
  _paq.push(["enableLinkTracking"]);
  _paq.push(["setTrackerUrl", "https://stats.example.com/matomo.php"]);
  _paq.push(["setSiteId", "14"]);
</script>
<script src="https://stats.example.com/matomo.js" async type="text/partytown"></script>

I also fixed issues with cors, so that mean web worker can fetch my analytics script because there are no more errors about cors

But cannot understand how can I forward push to array with value 'trackPageView' eg:

_paq.push(['trackPageView']);

If I execute manually on console it throws error

  _paq.push(['trackPageView']); 
_paq.push() was used but Matomo tracker was not initialized before the matomo.js file was loaded. Make sure to configure the tracker via _paq.push before loading matomo.js. Alternatively, you can create a tracker via Matomo.addTracker() manually and then use _paq.push but it may not fully work as tracker methods may not be executed in the correct order. 
Array [ "trackPageView" ]

Looks like party town itself loads, but cannot send anything to matomo image

rrolla avatar Dec 30 '22 04:12 rrolla

@rrolla, did you make by chance any progress in this? Thank you!

mhoev avatar Mar 18 '23 19:03 mhoev

@rrolla, did you make by chance any progress in this? Thank you!

No unfortunately no progress on this, I added in old way for now.

rrolla avatar Mar 18 '23 20:03 rrolla

Hello, I am also interested. If someone could guide us to make it work ?

slamer59 avatar Mar 24 '23 09:03 slamer59

I'm interested in this, please let me know of a solution

AlejandroAkbal avatar Jun 16 '23 08:06 AlejandroAkbal

I haven't tested anything, but just a wild guess. It could be that since you are forwarding _paq.push, partytown creates window._paq.push as a function to forward the event. But after that you are redefining it (window._paq = [];), so that might be the cause why it is not working. Good luck.

jpmaga avatar Jul 20 '23 08:07 jpmaga

I'm also facing this issue, any update?

aaronlin0122 avatar Sep 20 '23 21:09 aaronlin0122

I'm also facing this issue, any update?

got this from matomo:

Currently we do not sent access control headers with our JS files but this is something we are considering doing.

We have had several requests and made it a priority issue.

But I wouldn't get my hopes up. The rest of the support ticket indicates, that they don't really know what partytown is or what the header does. In their opinion csp setting of the site is wrong 🫠

woldtwerk avatar Sep 21 '23 07:09 woldtwerk

I have a working showcase that integrates Matomo within Shopify OS 2.0. Maybe it helps:

https://github.com/j0Shi82/shopify-partydawn

j0Shi82 avatar Nov 03 '23 12:11 j0Shi82

Thanks @j0Shi82 for sharing 👍

gioboa avatar Nov 04 '23 09:11 gioboa