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:
JavaScript
x
12
12
1
var Tawk_API = Tawk_API || {},
2
Tawk_LoadStart = new Date()
3
(function () {
4
var s1 = document.createElement('script')
5
s0 = document.getElementsByTagName('script')[0]
6
s1.async = true
7
s1.src = 'https://embed.tawk.to/[my_ID_HERE]/default'
8
s1.charset = 'UTF-8'
9
s1.setAttribute('crossorigin', '*')
10
s0.parentNode.insertBefore(s1, s0)
11
})()
12
And I put it on nuxt.config.js as well:
JavaScript
1
4
1
plugins: [
2
{ src: '~/plugins/tawk.js', ssr: false }
3
]
4
It didn’t work. It does show some compiled errors:
JavaScript
1
12
12
1
1:1 error Split initialized 'var' declarations into multiple statements
2
1:5 error Identifier 'Tawk_API' is not in camel case
3
1:16 error Identifier 'Tawk_API' is not in camel case
4
1:16 error 'Tawk_API' was used before it was defined
5
2:3 error Identifier 'Tawk_LoadStart' is not in camel case
6
2:3 error 'Tawk_LoadStart' is assigned a value but never used
7
2:29 error Unexpected space between function name and paren
8
3:3 error Unexpected newline between function and ( of function call
9
5:5 error 's0' is not defined
10
10:5 error 's0' is not defined
11
10:36 error 's0' is not defined
12
Advertisement
Answer
You could try to use a vue wrapper for tawk. vue-tawk
JavaScript
1
6
1
import Tawk from 'vue-tawk'
2
3
Vue.use(Tawk, {
4
tawkSrc: 'https://embed.tawk.to/5d5528ee2xxxxxxxxxxxx/default'
5
})
6