Change the widget or property based on page language

[Desktop] lets you create a widget or a property for each language on your website.

You can use JavaScript to automatically load the widget your visitor sees based on the language of the page they are viewing.

Please note: Only one widget at a time can function on the same website. The examples below load a single property/widget according to the criteria you choose. To use this method, you will need to remove the WordPress plugin, if it is being used.

Here are two models showing you how to set that up. Both require a functional knowledge of JavaScript.

To use each model, you’ll need to do the following: 

1. Create a widget for each language

Related: Changing your widget's language

2. Find your widget and property IDs.

Learn more here: Where can I find the property and widget IDs?

This solution may vary depending on how multi-language options are set up on your website. The code snippets below are for a website with a URL in the following format:

Model 1

To set a widget to appear based on the language of a page, use the following code. Then, to override and change the widget that appears, modify the getChatId function to return a specific chat id for each language.

Model 2

Here’s a way to change the property based on page language by modifying the `getChatId` function again and updating the return values for each language.

Changing the property connects your customers with the agents, statistics, shortcuts, and knowledge base of the new property. 

Learn more about adding multiple widgets to a website in this guide: How to add multiple widgets to a website with JavaScript

If you need additional assistance setting up multiple widgets on your site, visit our Developer Platform or reach out in the chat. We are here to help 24x7. Need additional help? Reach out to our support team or schedule a call.

Was this article helpful?

111 out of 179 liked this article

Still need help? Message Us