Can I get attribution info from _paq?

Can I use

_paq.push('getAttributionInfo')

or sim to get attribution info from the _paq API?

Hi,

I think the best way to call a JS method is like this

_paq.push([function () {
    var attributionInfo = this.getAttributionInfo();
    console.info(attributionInfo)
}]);

Thank you! How do you know this.getAttributionInfo() works? Couldn’t find it in the docs about _paq.

Hi,

You can find getAttributionInfo in the JS-tracking-client docs:

https://developer.matomo.org/api-reference/tracking-javascript#configuration-of-the-tracker-object

But I agree that this website needs a better search (which is already partly build)

Oh! So using this in _paq gets access to the JS API? Good to know. ^^

You could also use Piwik.getAsyncTracker().getAttributionInfo(), but it has one large disadvantage, which is solved by the _paq syntax:

Matomo loads asynchronous, so it is possible that your code runs before the piwik.js has even finished loading and would fail therefor. If you use _paq the function will be saved and run once Matomo has finished loading.

Right now I use setTimeout to wait until Piwik is done. Is there another way, like, register a callback function instead?

I think what I posted above should be about what you need:

_paq.push([function () {
    console.info("Matomo has finished loading")
}]);