Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Allow changing any Matomo configuration #174

Merged
merged 2 commits into from
Jun 2, 2020
Merged

Conversation

An-dz
Copy link
Contributor

@An-dz An-dz commented May 31, 2020

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 and setRequestMethod and noticed that it would not be optimal to write a specific case for each configuration possible. I remove the userId feature because it can be passed through this new object.

Copy link

@fcandi fcandi left a 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!!

@jonkoops jonkoops linked an issue Jun 2, 2020 that may be closed by this pull request
@@ -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`.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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');

Copy link

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!

Copy link
Owner

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.

Copy link
Contributor

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

linkTracking: false // optional, default value: true
linkTracking: false, // optional, default value: true
configurations: { // optional, default value: {}
// any valid matomo configuration
Copy link
Contributor

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?

Copy link

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

Copy link
Contributor Author

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',
    }
});

Copy link

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 👍

Copy link
Contributor

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?

@chrisvanmook
Copy link
Contributor

This looks like exactly what I am needing. So I can for example disable cookies, what I need to!!

Could you perhaps add an example how you would do this in the configuration object?

@An-dz
Copy link
Contributor Author

An-dz commented Jun 2, 2020

UserId has been reverted and added examples in the README.

@jonkoops jonkoops merged commit c62e616 into jonkoops:master Jun 2, 2020
@An-dz An-dz mentioned this pull request Jul 27, 2020
3 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cookies timeout / European laws
4 participants