tawk / tawk-messenger-react

Official React plugin for Tawk messenger
https://www.tawk.to
Other
23 stars 15 forks source link

Changes made through setAttributes are only reflected sporadically in tawkto dashboard #26

Open mleister97 opened 1 year ago

mleister97 commented 1 year ago

In my code, I use the SecureMode, and I have made sure that the method setAttributes is only called when all values are available. I see in the WebSocket connection that the data is being transmitted successfully. However, the callback function of setAttributes returns undefined, and none of the possible errors mentioned in the documentation. Sometimes, the attributes get updated in the dashboard, but sometimes they don't. Could it be that they are not being added live, or are there currently any issues?

import React, {useEffect, useRef, useState} from 'react';
import {useAuth} from "./auth/context";
import TawkMessengerReact from '@tawk.to/tawk-messenger-react';

function generateName() {...}

const TawkMessenger = () => {
    const tawkMessengerRef = useRef();
    const {user} = useAuth()
    const [isTawkLoaded, setIsTawkLoaded] = useState(false)

    useEffect(() => {
        if (tawkMessengerRef.current == null || user == null || !isTawkLoaded) return
        tawkMessengerRef.current.setAttributes({
            reference: user.id,
            name: generateName(user.firstName, user.lastName),
            email: user.email,
            hash: user.tawktoHash,
        }, function (error: unknown) {
            console.log(error)
        })
    }, [user?.tawktoHash, user?.firstName, user?.lastName, user?.email, user?.id, isTawkLoaded])

    return <TawkMessengerReact
        onLoad={() => { setIsTawkLoaded(true) }}
        propertyId="XXXXX"
        widgetId="XXXXX"
        ref={tawkMessengerRef}
    />
}

export default TawkMessenger

Websocket: image

Dashboard View:

tawkto

jaoaustero commented 2 months ago

Hello, this is correct since setAttributes is async in our backend and it takes time to reflect in the dashboard, If your data is prepared already before you load the widget, you can use the visitor API instead it's more realtime.