Uncaught TypeError: window.ga is not a function

We're trying to implement Site Search with a custom search field. However, if a user types something in the field and then hits "return", this error appears in the console:

st.js:73 Uncaught TypeError: window.ga is not a function
    at Object.n.Utils.pushToGA (st.js:73)
    at Swiftype.QueryContext.pQueryContext.pushQueryToGA (st.js:74)
    at Swiftype.QueryComposer.pQueryComposer.runSearch (st.js:74)
    at HTMLInputElement.<anonymous> (st.js:74)
    at HTMLInputElement.dispatch (st.js:25)
    at HTMLInputElement.y.handle (st.js:24)

What is this error and how do we fix it?

Thanks!

Hey there!

At a quick glance, it does appear to be a conflict with another asset on the page. Would it be possible to include a link to where this error can be observed along with any steps to reproduce it?

If you'd rather not include that information within a community post, please reach out to the Support team with the above information and context: https://www.elastic.co/support/welcome/swiftype

Thank you for your quick response.

To reproduce the error, add content to the search field (click the magnifying glass at the top of the page in the navigation) and hit the return key.

Hi: Even if I remove all other scripts from the page (locally), the error still appears.

So either there is something I need to add that I haven't or there seems to be an error in the st.js script itself.

It does appear to be a script related to your GA via GTM that may be butting heads with our embed snippet's built in behavior to pass the site search query value to your GA endpoint.

In the past I've seen asset load order being the culprit, so I did a quick test with a barebones HTML boilerplate and added your Swiftype embed script before the GTM script within the <head></head> container and then included the input element within the <body>.

Under these circumstances the search overlay performed as expected without triggering the error.

I'm afraid we're unable to support or debug non-Swiftype related scripts/conflicts, but if you're able to pinpoint a valid bug we can escalate to our engineering team.

I hope this helps!

Hmm, that's pretty weird. I pulled out our GA script, and every other script loading on the page, and the error still appears.

Is the swiftype script restricted to the domain? So that if my staging/local environment domains don't exactly match my site's domain, then it would throw that error? Is there somewhere I need to whitelist staging/dev domains?

That is odd. :thinking: There's no domain specific restriction for the script to function. For the tests where you've removed every script other than Swiftype, have you tried clearing the cookies/cache if loading from the same staging domain and/or doing the barebones template test?

I'm curious if there's some other (potentially) minified asset loading that's calling additional scripts.

It turns out there was an element on the page with id="ga". Removing that allowed swiftype to work without issue. ¯_(ツ)_/¯

Thanks for your help!

1 Like

Ah! The ol' name collision scenario. I'm glad you were able to sort it out, and thank you for following-up!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.