Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using tawk.to with Nuxt/Vue Application

Does anyone know how to use tawk.to in a Nuxt application?

I created a file "tawk.js" on my plugin folder with the following code:

var Tawk_API = Tawk_API || {},
  Tawk_LoadStart = new Date()
  (function () {
    var s1 = document.createElement('script')
    s0 = document.getElementsByTagName('script')[0]
    s1.async = true
    s1.src = 'https://embed.tawk.to/[my_ID_HERE]/default'
    s1.charset = 'UTF-8'
    s1.setAttribute('crossorigin', '*')
    s0.parentNode.insertBefore(s1, s0)
  })()

And I put it on nuxt.config.js as well:

  plugins: [
    { src: '~/plugins/tawk.js', ssr: false }
  ]

It didn't work. It does show some compiled errors:

1:1   error  Split initialized 'var' declarations into multiple statements
1:5   error  Identifier 'Tawk_API' is not in camel case
1:16  error  Identifier 'Tawk_API' is not in camel case
1:16  error  'Tawk_API' was used before it was defined
2:3   error  Identifier 'Tawk_LoadStart' is not in camel case
2:3   error  'Tawk_LoadStart' is assigned a value but never used
2:29  error  Unexpected space between function name and paren
3:3   error  Unexpected newline between function and ( of function call
5:5   error  's0' is not defined
10:5   error  's0' is not defined
10:36  error  's0' is not defined
like image 665
Fabio Zanchi Avatar asked Sep 14 '25 16:09

Fabio Zanchi


1 Answers

The best way to integrate tawk.to in nuxt project is to go to nuxt.config.js and add it as a script tag.

// nuxt.config.js
export default {
    // ...
    head: {
        // ...
        script: [
            // ...
            {
                hid: 'tawk.to',
                src:
                    'https://embed.tawk.to/5edf699a9e5f694422903412/default',
                defer: true
            }
        ]
    },
},
like image 175
Ashit Shah Avatar answered Sep 17 '25 04:09

Ashit Shah