mitjans / nuxt-posthog

Posthog module for Nuxt
https://nuxt-posthog.cmitjans.dev
MIT License
20 stars 1 forks source link

How to correctly set `persistence`? #28

Open stefanobartoletti opened 3 months ago

stefanobartoletti commented 3 months ago

Hi, thanks for this module!

I'm trying to correctly set the persistence: 'memory' to avoid using cookies, but I'm unable to do so apparently.

I tried to put this in my Nuxt config

  posthog: {
    clientOptions: {
      persistence: 'memory',
    },
  },

As it seems, by reading the docs here https://nuxt-posthog.cmitjans.dev/configuration, that this is the correct way to pass config options.

Anyway, on my deployed site, cookies are still set, and I need to prevent this.

I checked and it seems that these options are not correctly passed, I have some error thrown inside vscode

Screenshot_20240417_175347

Just to try, I added another random property (autocomplete just to test) and the highlighted number went to 46. Apparently it seems that the module is expecting me to pass all the possible properties down? Maybe there is some misconfiguration on my part, but I did everything by the docs, and it seems like there is some issue in merging the user settings with the default values .

Also, but I don't know if this can be an issue or not, by inspecting the module code, I noticed that the clientOptions is missing from the defaults, bu

Screenshot_20240417_181121

Let me know if I can provide more info or context :)

stefanobartoletti commented 3 months ago

Ok I did some more research, and I don't know if all of this is relevant as I am not familiar with the module inner workings, but here is what I get on the site frontend once loaded:

Screenshot_20240417_182457

As you can see the persistence property is nested inside clientOptions, inside the posthog key. So the previous error is not preventing this property to be passed, but still I suspect that is not merged correctly in the right place.

Before trying this module, I was using the basic script inclusion, like this

Screenshot_20240417_182955

And this worked perfectly, the property was correctly read and no cookies were set. persistence here is a property on the same object where also api_host is located, and at the same level. (I moved out of this config because I needed PostHog to correctly detect different pages, and with that config it didn't)

I hope you didn't mind the long report, I tried to provide every info that I deemed useful. And again, let me know if you need more info, I am willing to help in any way I can :)

mitjans commented 3 months ago

Thanks for the detailed information @stefanobartoletti! I'll take a look later today or tomorrow 🙏

stefanobartoletti commented 3 months ago

No worries, I'm not in a hurry, at the moment I resorted to manually implementing according to this https://posthog.com/docs/libraries/nuxt-js

mitjans commented 3 months ago

So, I've fixed the problem with the typings in the config file (thanks for spotting that!).

However, I cannot reproduce the issue in the module's playground. When I set the configuration to 'memory', no PostHog cookies are created and a new Session Id is created when the page is refreshed.

I'll try again with a different project after a pre-release of the module and let you know. 👍

mitjans commented 3 months ago

Hey @stefanobartoletti! Can you try with the new pre-release version 1.5.0?

stefanobartoletti commented 3 months ago

Thank you, I will try to test this as soon as possible but I'm quite busy these days. I will see if I can gather some time during the next couple of weeks.

stefanobartoletti commented 2 months ago

Sorry for the delay, I've been quite busy.

I tried to set up a new project within PostHog to test this, but it looks like in the free tier I'm not allowed to have more than one.

At the moment my main site, where I set up the script manually, is in quite important moment, and I need to keep the visits tracked steadily and without possible issues.

Do you have some suggestions about how I can find a way to test it nonetheless?

mitjans commented 2 months ago

Hey @stefanobartoletti sorry for the late answer.

Have you tried setting up a new PostHog account with a new email? Just for testing purposes. You should be able to test this without having to touch your production application.

Have you found if the problem persists after release 1.5.0?