Loschcode / vue-mixpanel

A simple Vue.js plugin for Mixpanel
https://laurent.tech
MIT License
38 stars 4 forks source link

The event is tracked twice if there is a redirect in function. #3

Closed ReDss-TS closed 3 years ago

ReDss-TS commented 3 years ago

I have component Register with method "success".

success() {
    this.$analytic.mixpanel.track('Sign Up', this.$analytic.mixpanel.getUserProperties());
    window.location = '/';
},

vue-mixpanel connected in my custom plugin Analytic

Vue.prototype.$analytic = {
    mixpanel: {
        track(eventName, properties) {
            mixpanelEventCallback(() => {
                this.identify();
                Vue.prototype.$mixpanel.track(eventName, properties);
            });
        },
        identify() {
            const userId = store.getters['user/getId'];

            if (userId !== undefined) {
                const identify = () => {
                    Vue.prototype.$mixpanel.identify(userId);
                };

                mixpanelEventCallback(identify);
            } else {
                mixpanelEventCallback(() => Vue.prototype.$mixpanel.reset());
            }
        },
    },
};

after logging in the event is tracked twice: image But the function is called only once. If I set debug: true, in the console I can see MIXPANEL REQUEST log before and after redirect. So it is possible that mixpanel holds some information in cookies about the request but because there is a redirect it repeats it.

Loschcode commented 3 years ago

@ReDss-TS are you sure your success() or mixpanelEventCallback() isn't called twice?