elgorditosalsero / react-gtm-hook

Easily manage the Google Tag Manager via Hook
https://elgorditosalsero-react-gtm-hook.netlify.app/
MIT License
220 stars 28 forks source link

ire is not defined #67

Closed vjaceslavhl closed 1 year ago

vjaceslavhl commented 2 years ago

Hey,

I'm trying to use your hook and for some events I'm getting weird error message:

Uncaught ReferenceError: ire is not defined
    at <anonymous>:1:1
    at gtm.js?id=GTM-AAAAAA:502:414
    at gtm.js?id=GTM-AAAAAA:503:118
    at b (gtm.js?id=GTM-AAAAAA:503:329)
    at Ge (gtm.js?id=GTM-AAAAAA:92:261)
    at e (gtm.js?id=GTM-AAAAAA:279:118)
    at gtm.js?id=GTM-AAAAAA:38:130
    at Array.<anonymous> (gtm.js?id=GTM-AAAAAA:280:475)
    at Object.execute (gtm.js?id=GTM-AAAAAA:280:231)
    at fs (gtm.js?id=GTM-AAAAAA:282:984)

which is this insertBefore part:

if ("SCRIPT" == String(h.nodeName).toUpperCase() && "text/gtmscript" == h.type) {
                            var n = H.createElement("script");
                            n.async = !1;
                            n.type = "text/javascript";
                            n.id = h.id;
                            n.text = h.text || h.textContent || h.innerHTML || "";
                            h.charset && (n.charset = h.charset);
                            var p = h.getAttribute("data-gtmsrc");
                            p && (n.src = p,
                            Yb(n, l));
                            d.insertBefore(n, null);
                            p || l()
                        } 

It's a simple event:

sendGTMData({ event: 'verification result code' });

I'm using it inside of useCallback in the custom hook, I'm honestly kinda struggle to find the solution, maybe you can point to the right direction?

Also in the debugger itself I can see that event is detected, plus additional event sent which is optimize.callback

Thank you

elgorditosalsero commented 1 year ago

Hey @vjaceslavhl, can you provide a stack blitz as I'm unable to reproduce it?

Sorry for the late answer.

vjaceslavhl commented 1 year ago

Hey @elgorditosalsero, The issue was resolved. I was wrong by saying that it's that simple event, it was related to "purchase" event.

It seems like google is quite strict with their "purchase" even data format and in my case we were missing one of the keys (honestly, don't remember which one), but ye, the problem was data format.

Pretty sure you can't do much from your side, but if google gives enough info from their side it would be great to have proper error handling and get info which event/key failing, but IIRC I've had exactly same error without any specifics with just native GTM implementation.

Thanks anyway