MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
866 stars 67 forks source link

Remove query parameters #333

Open cosbgn opened 3 years ago

cosbgn commented 3 years ago

Most social networks and ad providers add query parameters to links, things like (fclid, gclid, etc).

On analytics.js there was a way to ignore query parameters, this has been removed on GA4 and now needs to be done on site level (Something like: document.location.hostname + document.location.pathname).

Is there a way to do this automatically when page tracking is on?

cosbgn commented 3 years ago

Closing because if I understood correctly from another issue I just need to add: pageTrackerUseFullPath: true to the options. If I'm wrong please let me know. Thanks a lot!

cosbgn commented 3 years ago

Reopening, this because the pageTrackerUseFullPath does the opposite, is shows query parameters. I want instead to hide them, which should be the default but it's not working for me. I'm using the plugin with nuxt like this:

import Vue from 'vue';
import VueGtag from 'vue-gtag';

export default ({ isDev, app }) => {
    if (!isDev){
        Vue.use(VueGtag, {
            config: { id: 'G-XXX' }
        },
        app.router);
    } else {
        console.log("Skipping GA in localhost")
    }
}

I think the issue might be app.router ?

I'm using V1 with vue2

mwargan commented 2 years ago

@Cosbgn did you ever find a solution? I'm using now V2 with Vue3 but still have this issue. Ended up disabling pageTracking and writing a custom implementation on afterEach:

const pathStayedTheSame = (to: any, from: any) => {
    if (from && Object.keys(to.query).length) {
        if (to.fullPath.split('?')[0] == from.fullPath.split('?')[0]) return true;
    }
    return false;
};
///... Other code, then in router.afterEach
if (pathStayedTheSame(to, from)) {
    return;
}

Implemented thanks to the idea from https://github.com/vuejs/vue-router/issues/2072#issuecomment-605502951