├── images
└── tawk-react-logo.png
├── src
├── utils
│ ├── helper.js
│ └── widget.js
├── __tests__
│ ├── Install.spec.js
│ └── TawkMessenger.spec.js
└── index.js
├── LICENSE
├── CHANGELOG.md
├── vite.config.js
├── .eslintrc.js
├── docs
├── how-to-use.md
└── api-reference.md
├── package.json
├── README.md
├── .gitignore
└── dist
├── tawk-messenger-react.umd.js
└── tawk-messenger-react.es.js
/images/tawk-react-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tawk/tawk-messenger-react/HEAD/images/tawk-react-logo.png
--------------------------------------------------------------------------------
/src/utils/helper.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @param {String} value - A data that needs to be validated
3 | * @returns - Boolean
4 | */
5 | const isValidString = (value) => {
6 | if (!value || value.length === 0) {
7 | return false;
8 | }
9 |
10 | return value !== null && value !== undefined && typeof value === 'string';
11 | };
12 |
13 |
14 | export {
15 | isValidString
16 | };
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2022 tawk.to inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | **Keep track of every change of the tawk-messenger-react.**
3 | This changelog list all additions and updates to the plugin, in chronological order.
4 | All notable changes in this project will be documented in this file.
5 |
6 |
7 | ## [2.1.0] - 2025-06-12
8 | ### Breaking Changes
9 | - **library:** Rename all API names to have `tawk` prefix to avoid name collissions ([#40](https://github.com/tawk/tawk-messenger-react/pull/40)).
10 |
11 | ### Major Changes
12 | - **library:** Add `autoStart`, `tawkStart`, `tawkShutdown` new APIs to manually start and end the socket connection ([#29](https://github.com/tawk/tawk-messenger-react/pull/29)).
--------------------------------------------------------------------------------
/vite.config.js:
--------------------------------------------------------------------------------
1 | import path from 'path';
2 | import { defineConfig } from 'vite'
3 | import react from '@vitejs/plugin-react'
4 |
5 | // https://vitejs.dev/config/
6 | export default defineConfig({
7 | plugins: [react()],
8 |
9 | build : {
10 | lib : {
11 | entry : path.resolve(__dirname, 'src/index.js'),
12 | name : 'tawk-messenger-react',
13 | fileName : (format) => `tawk-messenger-react.${format}.js`
14 | },
15 | rollupOptions : {
16 | external : ['react'],
17 |
18 | output : {
19 | globals : {
20 | react : 'React'
21 | }
22 | }
23 | }
24 | }
25 | })
26 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root : true,
3 | env : {
4 | node : true,
5 | jest : true,
6 | es2020 : true
7 | },
8 | extends : [
9 | 'plugin:react/recommended',
10 | 'plugin:react/jsx-runtime',
11 | 'eslint:recommended'
12 | ],
13 | ignorePatterns : ['/dist/**'],
14 | rules : {
15 | 'no-console' : ['error', { allow : ['warn', 'error'] }],
16 | 'no-debugger' : 'error',
17 | 'no-var' : 'off',
18 | semi : ['error', 'always'],
19 | indent : [1, 'tab'],
20 | 'space-before-function-paren' : [
21 | 'warn',
22 | {
23 | anonymous : 'always',
24 | named : 'never'
25 | }
26 | ],
27 | 'key-spacing' : [
28 | 'warn',
29 | {
30 | beforeColon : true
31 | }
32 | ],
33 | 'operator-linebreak' : ['error', 'after'],
34 | 'no-nested-ternary' : 'error',
35 | quotes : ['error', 'single'],
36 | 'arrow-parens' : ['error', 'always'],
37 | 'react/jsx-uses-react' : 'off',
38 | 'react/react-in-jsx-scope' : 'off',
39 | 'no-redeclare' : 'off'
40 | },
41 | settings : {
42 | react : {
43 | version : 'detect'
44 | }
45 | },
46 | parser : 'babel-eslint'
47 | };
--------------------------------------------------------------------------------
/src/utils/widget.js:
--------------------------------------------------------------------------------
1 | /* global document, window */
2 | /* eslint-disable no-use-before-define */
3 |
4 | /**
5 | * @param {Object} - Tawk widget required properties
6 | */
7 | const loadScript = ({propertyId = '', widgetId = '', embedId = '', basePath = 'tawk.to', autoStart = true}) => {
8 | if (embedId.length) {
9 | /**
10 | * If the element with embedId as id we will create a new clement
11 | */
12 | if (!document.getElementById(embedId)) {
13 | const element = document.createElement('div');
14 | element.id = embedId;
15 |
16 | document.body.appendChild(element);
17 | }
18 |
19 | window.Tawk_API.embedded = embedId;
20 | }
21 |
22 | if (!autoStart) {
23 | window.Tawk_API.autoStart = autoStart;
24 | }
25 |
26 | const script = document.createElement('script');
27 | script.async = true;
28 | script.src = `https://embed.${basePath}/${propertyId}/${widgetId}`;
29 | script.charset = 'UTF-8';
30 | script.setAttribute('crossorigin', '*');
31 |
32 | const firstScript = document.getElementsByTagName('script')[0];
33 | firstScript.parentNode.insertBefore(script, firstScript);
34 | };
35 |
36 |
37 | export {
38 | loadScript
39 | };
--------------------------------------------------------------------------------
/docs/how-to-use.md:
--------------------------------------------------------------------------------
1 | # How to Use
2 | Here are the basic of how to use callbacks and expose functions from the plugin. You can see the
3 | list of APIs in this [API reference](api-reference.md).
4 |
5 | ## Expose functions
6 | To access the expose functions, you will need to use **useRef** from react. Create a constant
7 | variable that will hold the **useRef()** and pass it in **TawkMessengerReact** component as a prop.
8 |
9 | ```js
10 | import { useRef } from 'react';
11 | import TawkMessengerReact from '@tawk.to/tawk-messenger-react';
12 |
13 | function App() {
14 | const tawkMessengerRef = useRef();
15 |
16 | const handleTawkMinimize () => {
17 | tawkMessengerRef.current.tawkMinimize();
18 | };
19 |
20 | return (
21 |
22 |
23 |
24 |
28 |
29 | );
30 | }
31 | ```
32 |
33 | ## Using Callbacks
34 | Using the API callbacks, pass a function as props on the callback you will used.
35 |
36 | ```js
37 | function App() {
38 | const tawkOnLoad = () => {
39 | // Do something here
40 | };
41 |
42 | return (
43 |
6 |
7 |
8 |
9 | ## Features
10 | * Using React Hooks
11 | * Documented and self-explaining methods
12 | * Small size without any external libraries
13 | * All Javascript API methods are available
14 | * Maintained by the [tawk.to](https://www.tawk.to/) team.
15 |
16 |
17 |
18 | ## Installation
19 | The plugins are available from the node and yarn package managers.
20 | ```bash
21 | # Node
22 | npm install @tawk.to/tawk-messenger-react
23 |
24 | # Yarn
25 | yarn add @tawk.to/tawk-messenger-react
26 | ```
27 |
28 |
29 |
30 | ## Quickstart
31 | Import **tawk-messenger-react** into the App.js file of your **src/** folder. The **propertyId** and **widgetId** will
32 | be found on your tawk Dashboard.
33 |
34 | Log in to your account and go to **Administration > Channels > Chat Widget**.
35 |
36 | When using the API, you will need to use the **useRef** to access the object functions from the **tawk-messenger-react** component.
37 |
38 | ```js
39 | import TawkMessengerReact from '@tawk.to/tawk-messenger-react';
40 |
41 | function App() {
42 | return (
43 |
83 | );
84 | }
85 | ```
86 |
87 |
88 |
89 | ## tawkOnStatusChange
90 | Callback function invoked when the page status changes. The function will receive the changed
91 | status which will be either online, away or offline. This callback is not supported in pop out
92 | chat window.
93 |
94 | ```js
95 | function App() {
96 | const tawkOnStatusChange = (status) => {
97 | // place your code here
98 | }
99 |
100 | return (
101 |
102 |
104 |
105 | );
106 | }
107 | ```
108 |
109 |
110 |
111 | ## tawkOnBeforeLoad
112 | Callback function invoked right when Tawk_API is ready to be used and before the widget is rendered.
113 | This callback is not supported in pop out chat window.
114 |
115 | ```js
116 | function App() {
117 | const tawkOnBeforeLoad = () => {
118 | // place your code here
119 | }
120 |
121 | return (
122 |
123 |
125 |
126 | );
127 | }
128 | ```
129 |
130 |
131 |
132 | ## tawkOnChatMaximized
133 | Callback function invoked when the widget is maximized. This callback is not supported in pop out
134 | chat window.
135 |
136 | ```js
137 | function App() {
138 | const tawkOnChatMaximized = () => {
139 | // place your code here
140 | }
141 |
142 | return (
143 |
144 |
146 |
147 | );
148 | }
149 | ```
150 |
151 |
152 |
153 | ## tawkOnChatMinimized
154 | Callback function invoked when the widget is minimized. This callback is not supported in pop out
155 | chat window.
156 |
157 | ```js
158 | function App() {
159 | const tawkOnChatMinimized = () => {
160 | // place your code here
161 | }
162 |
163 | return (
164 |
165 |
167 |
168 | );
169 | }
170 | ```
171 |
172 |
173 |
174 | ## tawkOnChatHidden
175 | Callback function invoked when the widget is hidden. This callback is not supported in pop out chat
176 | window.
177 |
178 | ```js
179 | function App() {
180 | const tawkOnChatHidden = () => {
181 | // place your code here
182 | }
183 |
184 | return (
185 |
186 |
188 |
189 | );
190 | }
191 | ```
192 |
193 |
194 |
195 | ## tawkOnChatStarted
196 | Callback function invoked when the widget is started.
197 |
198 | ```js
199 | function App() {
200 | const tawkOnChatStarted = () => {
201 | // place your code here
202 | }
203 |
204 | return (
205 |
206 |
208 |
209 | );
210 | }
211 | ```
212 |
213 |
214 |
215 | ## tawkOnChatEnded
216 | Callback function invoked when the widget is ended. This callback is not supported in pop out chat
217 | window.
218 |
219 | ```js
220 | function App() {
221 | const tawkOnChatEnded = () => {
222 | // place your code here
223 | }
224 |
225 | return (
226 |
227 |
229 |
230 | );
231 | }
232 | ```
233 |
234 |
235 |
236 | ## tawkOnPrechatSubmit
237 | Callback function invoked when the Pre-Chat Form is submitted. The submitted form data is passed to
238 | the function. This callback is not supported in pop out chat window.
239 |
240 | ```js
241 | function App() {
242 | const tawkOnPrechatSubmit = (data) => {
243 | // place your code here
244 | }
245 |
246 | return (
247 |
248 |
250 |
251 | );
252 | }
253 | ```
254 |
255 |
256 |
257 | ## tawkOnOfflineSubmit
258 | Callback function invoked when the Offline form is submitted. The submitted form data is passed to
259 | the function. Form data will contain {name : ”, email : ”, message : ”, questions : []}. This
260 | callback is not supported in pop out chat window.
261 |
262 | ```js
263 | function App() {
264 | const tawkOnOfflineSubmit = (data) => {
265 | // place your code here
266 | }
267 |
268 | return (
269 |
270 |
272 |
273 | );
274 | }
275 | ```
276 |
277 |
278 |
279 | ## tawkOnChatMessageVisitor
280 | Callback function invoked when message is sent by the visitor. The message is passed to the
281 | function. This callback is not supported in pop out chat window.
282 |
283 | ```js
284 | function App() {
285 | const tawkOnChatMessageVisitor = (message) => {
286 | // place your code here
287 | }
288 |
289 | return (
290 |
291 |
293 |
294 | );
295 | }
296 | ```
297 |
298 |
299 |
300 | ## tawkOnChatMessageAgent
301 | Callback function invoked when message is sent by the agent. The message is passed to the function.
302 | This callback is not supported in pop out chat window.
303 |
304 | ```js
305 | function App() {
306 | const tawkOnChatMessageAgent = (message) => {
307 | // place your code here
308 | }
309 |
310 | return (
311 |
312 |
314 |
315 | );
316 | }
317 | ```
318 |
319 |
320 |
321 | ## tawkOnChatMessageSystem
322 | Callback function invoked when message is sent by the system. The message is passed to the function.
323 | This callback is not supported in pop out chat window.
324 |
325 | ```js
326 | function App() {
327 | const tawkOnChatMessageSystem = (message) => {
328 | // place your code here
329 | }
330 |
331 | return (
332 |
333 |
335 |
336 | );
337 | }
338 | ```
339 |
340 |
341 |
342 | ## tawkOnAgentJoinChat
343 | Callback function invoked when an agent joins the chat. The data is passed to the function. Will
344 | contain {name : ”, position : ”, image : ”, id : ”}. This callback is not supported in pop out chat
345 | window.
346 |
347 | ```js
348 | function App() {
349 | const tawkOnAgentJoinChat = (data) => {
350 | // place your code here
351 | }
352 |
353 | return (
354 |
355 |
357 |
358 | );
359 | }
360 | ```
361 |
362 |
363 |
364 | ## tawkOnAgentLeaveChat
365 | Callback function invoked when an agent leaves the chat. The data is passed to the function. Will
366 | contain {name : ”, id : ”}. This callback is not supported in pop out chat window.
367 |
368 | ```js
369 | function App() {
370 | const tawkOnAgentLeaveChat = (data) => {
371 | // place your code here
372 | }
373 |
374 | return (
375 |
376 |
378 |
379 | );
380 | }
381 | ```
382 |
383 |
384 |
385 | ## tawkOnChatSatisfaction
386 | Callback function invoked when an agent leaves the chat. The satisfaction is passed to the function.
387 | -1 = dislike | 0 = neutral | 1 = like. This callback is not supported in pop out chat window.
388 |
389 | ```js
390 | function App() {
391 | const tawkOnChatSatisfaction = (satisfaction) => {
392 | // place your code here
393 | }
394 |
395 | return (
396 |
397 |
399 |
400 | );
401 | }
402 | ```
403 |
404 |
405 |
406 | ## tawkOnVisitorNameChanged
407 | Callback function invoked when the visitor manually changes his name. The visitorName is passed to
408 | the function. This callback is not supported in pop out chat window.
409 |
410 | ```js
411 | function App() {
412 | const tawkOnVisitorNameChanged = (visitorName) => {
413 | // place your code here
414 | }
415 |
416 | return (
417 |
418 |
420 |
421 | );
422 | }
423 | ```
424 |
425 |
426 |
427 | ## tawkOnFileUpload
428 | Callback function invoked when a file is uploaded. The link to the uploaded file is passed to the
429 | function. This callback is not supported in pop out chat window.
430 |
431 | ```js
432 | function App() {
433 | const tawkOnFileUpload = (link) => {
434 | // place your code here
435 | }
436 |
437 | return (
438 |
439 |
441 |
442 | );
443 | }
444 | ```
445 |
446 |
447 |
448 | ## tawkOnTagsUpdated
449 | Callback function invoked when a tag is updated.
450 |
451 | ```js
452 | function App() {
453 | const tawkOnTagsUpdated = (data) => {
454 | // place your code here
455 | }
456 |
457 | return (
458 |
459 |
461 |
462 | );
463 | }
464 | ```
465 |
466 |
467 |
468 | ## tawkOnUnreadCountChanged
469 | Callback function invoked when active conversation unread count changed.
470 |
471 | ```js
472 | function App() {
473 | const tawkOnUnreadCountChanged = (count) => {
474 | // place your code here
475 | }
476 |
477 | return (
478 |
479 |
481 |
482 | );
483 | }
484 | ```
485 |
486 |
487 |
488 | ## tawkOnLoaded
489 | Returns a value (true or undefined) indicating when the plugin is ready.
490 |
491 | ```js
492 | tawkMessengerRef.current.tawkOnLoaded();
493 |
494 | // Example
495 |
496 | function App() {
497 | const tawkMessengerRef = useRef();
498 |
499 | const tawkOnLoad = () => {
500 | if (tawkMessengerRef.current.tawkOnLoaded()) {
501 | // do something before loaded
502 | }
503 | };
504 |
505 | return (
506 |
507 |
510 |
511 | );
512 | }
513 | ```
514 |
515 |
516 |
517 | ## tawkOnBeforeLoaded
518 | Returns a value (true of undefined) indicating when plugin is initialized.
519 |
520 | ```js
521 | tawkMessengerRef.current.tawkOnBeforeLoaded();
522 |
523 | // Example
524 |
525 | function App() {
526 | const tawkMessengerRef = useRef();
527 |
528 | const tawkOnLoad = () => {
529 | if (tawkMessengerRef.current.tawkOnBeforeLoaded()) {
530 | // do something before loaded
531 | }
532 | };
533 |
534 | return (
535 |
536 |
539 |
540 | );
541 | }
542 | ```
543 |
544 |
545 |
546 | ## tawkWidgetPosition
547 | Returns a string for current position of the widget.
548 |
549 | ```js
550 | tawkMessengerRef.current.tawkWidgetPosition();
551 |
552 | // Example
553 |
554 | function App() {
555 | const tawkMessengerRef = useRef();
556 |
557 | const tawkOnLoad = () => {
558 | if (tawkMessengerRef.current.tawkWidgetPosition() === 'br') {
559 | // do something if the widget is at bottom right
560 | }
561 | };
562 |
563 | return (
564 |
565 |
568 |
569 | );
570 | }
571 | ```
572 |
573 |
574 |
575 | ## tawkVisitor
576 | Object used to set the visitor name and email. Do not place this object in a function, as the
577 | values need to be available before the widget script is downloaded.
578 |
579 | Setting or changing the values after the widget script has been downloaded will not send the
580 | values to the dashboard.
581 |
582 | If the name and email will not be available on load time (eg single page app, ajax login), then
583 | use the [setAttributes](#setAttributes) function instead.
584 |
585 | ```js
586 | tawkMessengerRef.current.tawkVisitor({
587 | name : 'name',
588 | email : 'email@email.com'
589 | });
590 |
591 | // Example
592 |
593 | function App() {
594 | const tawkMessengerRef = useRef();
595 |
596 | const tawkOnLoad = () => {
597 | tawkMessengerRef.current.tawkVisitor({
598 | name : 'name',
599 | email : 'email@email.com'
600 | });
601 | };
602 |
603 | return (
604 |
605 |
608 |
609 | );
610 | }
611 | ```
612 |
613 |
614 |
615 | ## autoStart
616 | If set to true, it will auto-start the Tawk socket connection for chat services. If set to false,
617 | you will need to manually call the start API. It will not register and connect to the dashboard
618 | if this is set to false.
619 |
620 | ```js
621 | import TawkMessengerReact from '@tawk.to/tawk-messenger-react';
622 |
623 | function App() {
624 | return (
625 |
1111 | );
1112 | }
1113 | ```
1114 |
1115 |
1116 |
1117 | ## tawkSetAttributes
1118 | Set custom metadata regarding this chat/visitor.
1119 |
1120 | This function takes in two values: attribute and callback.
1121 |
1122 | The attribute value is of the object data type, which is a key value pair.
1123 |
1124 | The key is of the string data type and can contain only alphanumeric characters and ‘-‘ (dash).
1125 |
1126 | You can also use this function to set the visitor name and email. However, you will need to enable
1127 | the secure mode first and also supply the calculated hash value in this function.
1128 |
1129 | Refer to the secure mode section below on how to do this.
1130 |
1131 | The reason it needs to be in [secure mode](#securemode) is to ensure data integrity — to ensure the
1132 | value sent from the widget to the dashboard is true and has not been tampered with.
1133 |
1134 | The callback, which is a function, will be invoked to notify whether the save failed.
1135 |
1136 | Error messages returned:
1137 |
1138 | 1. INVALID_ATTRIBUTES: No attributes were sent
1139 | 1. SESSION_EXPIRED: The visitor’s current session has expired
1140 | 1. SERVER_ERROR: Internal server error
1141 | 1. ACCESS_ERROR: Error in accessing the page
1142 | 1. ATTRIBUTE_LIMIT_EXCEEDED: Total custom attributes (excluding name, email and hash) is 50
1143 | 1. CONTAINS_INVALID_KEY: Custom key is not alphanumeric or dash (keys will be lower case)
1144 | 1. CONTAINS_INVALID_VALUE: Custom value is empty or the total length is more than 255 characters
1145 |
1146 | ```js
1147 | tawkMessengerRef.current.tawkSetAttributes(attributes, callback);
1148 |
1149 | // Example
1150 |
1151 | function App() {
1152 | const tawkMessengerRef = useRef();
1153 |
1154 | const tawkOnLoad = () => {
1155 | tawkMessengerRef.current.tawkSetAttributes({
1156 | id : 'A1234',
1157 | store : 'Midvalley'
1158 | }, function(error) {
1159 | // do something if error
1160 | });
1161 |
1162 | // Example for setting name and email
1163 |
1164 | tawkMessengerRef.current.setAttributes({
1165 | name : 'name',
1166 | store : 'name@email.com',
1167 | hash : 'has value'
1168 | }, function(error) {
1169 | // do something if error
1170 | });
1171 | };
1172 |
1173 | return (
1174 |
1175 |
1178 |
1179 | );
1180 | }
1181 | ```
1182 |
1183 |
1184 |
1185 | ## tawkAddEvent
1186 | Set a custom event to chat.
1187 | This function takes in 3 values: event name, optional metadata and callback.
1188 |
1189 | The event name is of the string data type and can contain only alphanumeric characters and ‘-‘ (dash)
1190 |
1191 | The callback which is a function will be invoked to notify whether the save failed.
1192 |
1193 | INVALID_EVENT_NAME, INVALID_ATTRIBUTES, ATTRIBUTE_LIMIT_EXCEEDED, CONTAINS_INVALID_KEY,
1194 | CONTAINS_INVALID_VALUE, SESSION_EXPIRED, SERVER_ERROR
1195 |
1196 | ```js
1197 | tawkMessengerRef.current.tawkAddEvent(eventName, metaData, callback);
1198 |
1199 | // Example
1200 |
1201 | function App() {
1202 | const tawkMessengerRef = useRef();
1203 |
1204 | const tawkOnLoad = () => {
1205 | tawkMessengerRef.current.tawkAddEvent(
1206 | 'requested-quotation',
1207 | function(error) {
1208 | // do something if error
1209 | }
1210 | );
1211 |
1212 | // Example with metadata
1213 |
1214 | tawkMessengerRef.current.tawkAddEvent(
1215 | 'requested-quotation',
1216 | {
1217 | sku : 'A0012',
1218 | name : 'Jeans',
1219 | price : '50'
1220 | }
1221 | function(error) {
1222 | // do something if error
1223 | }
1224 | );
1225 | };
1226 |
1227 | return (
1228 |
1229 |
1232 |
1233 | );
1234 | }
1235 | ```
1236 |
1237 |
1238 |
1239 | ## tawkAddTags
1240 | Add tags to the chat.
1241 | This function takes in two values; tags and callback.
1242 | This is of the array data type.
1243 | The content of the tags should be of the string data type.
1244 |
1245 | The total number of tags is 10.
1246 | The callback, which is a function, will be invoked to notify whether the save failed.
1247 |
1248 | INVALID_TAGS, TAG_LIMIT_EXCEEDED, VERSION_CONFLICT, SESSION_EXPIRED, SERVER_ERROR
1249 |
1250 | ```js
1251 | tawkMessengerRef.current.tawkAddTags(tags, callback);
1252 |
1253 | // Example
1254 |
1255 | function App() {
1256 | const tawkMessengerRef = useRef();
1257 |
1258 | const tawkOnLoad = () => {
1259 | tawkMessengerRef.current.tawkAddTags(
1260 | [
1261 | 'hello',
1262 | 'world'
1263 | ],
1264 | function(error) {
1265 | // do something if error
1266 | }
1267 | );
1268 | };
1269 |
1270 | return (
1271 |
1272 |
1275 |
1276 | );
1277 | }
1278 | ```
1279 |
1280 |
1281 |
1282 | ## tawkRemoveTags
1283 | Remove tags from the chat.
1284 | This function takes in two values: tags and callback.
1285 | This is of the array data type.
1286 | The content of the tags should be of the string data type.
1287 |
1288 | The callback, which is a function, will be invoked to notify whether the save failed.
1289 |
1290 | INVALID_TAGS, TAG_LIMIT_EXCEEDED, SESSION_EXPIRED, SERVER_ERROR
1291 |
1292 | ```js
1293 | tawkMessengerRef.current.tawkRemoveTags(tags, callback);
1294 |
1295 | // Example
1296 |
1297 | function App() {
1298 | const tawkMessengerRef = useRef();
1299 |
1300 | const tawkOnLoad = () => {
1301 | tawkMessengerRef.current.tawkRemoveTags(
1302 | [
1303 | 'hello',
1304 | 'world'
1305 | ],
1306 | function(error) {
1307 | // do something if error
1308 | }
1309 | );
1310 | };
1311 |
1312 | return (
1313 |
1314 |
1317 |
1318 | );
1319 | }
1320 | ```
1321 |
1322 |
1323 |
1324 | ## secureMode
1325 | Secure method is to ensure the data you are sending is actually from you.
1326 |
1327 | To enable secure mode, embed following code on your page.
1328 |
1329 | The hash is server side generated HMAC using SHA256, the user’s email and your site’s API key.
1330 |
1331 | You can get your API key from **Admin>Property Settings**.
1332 |
1333 | ```js
1334 | tawkMessengerRef.current.visitor({
1335 | name : 'name',
1336 | email : 'email@email.com'
1337 | hash : ''
1338 | });
1339 | ```
1340 |
1341 | ## switchWidget
1342 | Disconnect the current widget connection, logout if it has existing user login and switch to
1343 | another widget.
1344 |
1345 | ```js
1346 | tawkMessengerRef.current.switchWidget(options);
1347 |
1348 | // Example
1349 |
1350 | function App() {
1351 | const tawkMessengerRef = useRef();
1352 |
1353 | const onLoad = () => {
1354 | tawkMessengerRef.current.switchWidget({
1355 | propertyId ; 'property_id',
1356 | widgetId : 'widget_id'
1357 | }, function() {
1358 | // do something
1359 | });
1360 | };
1361 |
1362 | return (
1363 |
1364 |
1367 |
1368 | );
1369 | }
1370 | ```
1371 |
1372 | ## customstyle
1373 | Object used to update the widget styling. Currently only supports zIndex style. Do not place this
1374 | object in a function, as the values need to be available before the widget script is downloaded.
1375 | Setting or changing the values after the widget script has been downloaded will not update the
1376 | widget’s style.
1377 |
1378 | ### zIndex
1379 | ```js
1380 |
1382 |
1383 | // Example
1384 |
1385 | function App() {
1386 | return (
1387 |