Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with vue3 + Inertia #136

Open
eele94 opened this issue Mar 13, 2023 · 3 comments
Open

Doesn't work with vue3 + Inertia #136

eele94 opened this issue Mar 13, 2023 · 3 comments

Comments

@eele94
Copy link

eele94 commented Mar 13, 2023

I can't get it to work, because Inertia uses Ziggy route function to pass the routes instead of the default vue router.

Does anyone have an example for working with inertia?

@Repox
Copy link

Repox commented Aug 24, 2023

I can't get it to work, because Inertia uses Ziggy route function to pass the routes instead of the default vue router.

Ziggy doesn't provide routing like the Vue Router does. Ziggy is just a help in terms of using named routes from Laravel.

Does anyone have an example for working with inertia?

My solution has been the following:

import VueMatomo from 'vue-matomo'

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({el, App, props, plugin, title}) {
        const app = createApp({render: () => h(App, props)})
            .use(plugin)
            .use(ZiggyVue)
            .use(VueMatomo, {
                host: 'https://matomo.example.com',
                siteId: 1,
            })
            .mount(el);

        router.on('navigate', (event) => {
                window._paq.push(['trackPageView']);

                // If you want to track users as well
                if(event.detail.page.props.auth.user) {
                    window._paq.push(['setUserId', page.props.auth.user.id]);
                }
        });

        return app;
    },
    progress: {
        color: '#4B5563',
    },
});

@gde-pass
Copy link

@Repox Your implementation seems to work but not fully, i do have some logs on my matomo dashboard but not every pages visited are logged ...

@gde-pass
Copy link

gde-pass commented Aug 31, 2023

This is how i fixed the issue with Vue2 + Inertia + Ziggy + Vite:

  setup: ({ el, App, props, plugin }) => {
    Vue.use(plugin);
    Vue.use(VueMatomo, {
      host: import.meta.env.VITE_MATOMO_URL,
      siteId: import.meta.env.VITE_MATOMO_SITE_ID,
    });

    router.on('navigate', (event) => {
      window._paq.push(['setCustomUrl', event.detail.page.url]);
      window._paq.push(['trackPageView']);
    });

    new Vue({
      i18n,
      pinia,
      render: (h) => h(App, props),
    }).$mount(el);
  },

With the following line:

window._paq.push(['setCustomUrl', event.detail.page.url]);

I have been able to fix the issue where i see on the matomo dashboard a user navigating always on the same url while he actually navigate to differente pages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants