-
Notifications
You must be signed in to change notification settings - Fork 63
Allow changing any Matomo configuration #174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like exactly what I am needing. So I can for example disable cookies, what I need to!!
packages/js/README.md
Outdated
@@ -41,14 +41,16 @@ Before you're able to use this Matomo Tracker you need to initialize Matomo with | |||
const MatomoInstance = new window.MatomoTracker({ | |||
urlBase: 'https://LINK.TO.DOMAIN', | |||
siteId: 3, // optional, default value: `1` | |||
userId: 'UID76903202', // optional, default value: `undefined`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would introduce a breaking change, so I think for now we should leave it. The way we initialise the instance isn't perfect though, so we're going to think about how we can improve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the version is v0 I would expect breaking changes in the API, but it can be reverted, no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we will probably change the API soon so this can be done more explicitly with chained calls on the instance rather than passing all the possible options in a config. We don't want to put more breaking changes before that as it might confuse users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that the new API will be something like this?
instance
.urlBase('https://LINK.TO.DOMAIN')
.siteId(3)
.setUserId('example_id')
.disableCookies()
.setSecureCookie(true)
.setRequestMethod('POST');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be awesome, too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is basically what I have in mind as well. That and some better JSDoc for the functions plus a generic function to push entries into window._paq
in case we don't have the method in our library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's really nice! Created an issue: #176
packages/js/README.md
Outdated
linkTracking: false // optional, default value: true | ||
linkTracking: false, // optional, default value: true | ||
configurations: { // optional, default value: {} | ||
// any valid matomo configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an example of a configuration here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For exmaple, like so:
const matomoInstance = createInstance({
urlBase: 'https://matomo.example.com',
siteId: example_id,
configurations: [
['setUserId', 'example_id'],
['disableCookies', true]
]
})
Alternatively, it could be an Array of objects. The official syntax for disabling cookies is:
window._paq.push(['disableCookies']);
So maybe, it would be nice to make the second element of the array optional.
Andreas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fcandi With this code the current way is like this:
const matomoInstance = createInstance({
urlBase: 'https://matomo.example.com',
siteId: example_id,
configurations: {
setUserId: 'example_id',
disableCookies: true,
setSecureCookie: true,
setRequestMethod: 'POST',
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, its nice this way 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@An-dz Nice! could you add that to the readme?
Could you perhaps add an example how you would do this in the |
UserId has been reverted and added examples in the README. |
This commit adds a
configurations
key in the instance that allows passing any key/value pair.It allows passing any Matomo configuration without the need to write a specific case for each Matomo config.
I wrote this to be able to pass
setSecureCookie
andsetRequestMethod
and noticed that it would not be optimal to write a specific case for each configuration possible. I remove theuserId
feature because it can be passed through this new object.