Detecting URL query parameters in widget URL rules

Created by Seb Coulthread, Modified on Tue, 23 Apr 2024 at 09:40 PM by Seb Coulthread

Is it possible to detect URL query parameters in the widget editor?

A URL is broken down into the following elements:

What Is a URL? Meaning, Structure, and Optimization Tips

URLs are used within Talkative in two places to determine which content to display to the website visitor:

1. The widget config page rules. Determined by the Talkative server.

2. The card rules (within the widget config). Determined by the rules within the widget config (that are loaded on the page).

 

1. Widget Config Page Rules 

The Parameter String is not detected by default in the Talkative widget URL settings.

For example, if you want to have different widgets for the following URLs:

https://example.com/products?breed=cats

https://example.com/products?breed=dogs

Then you cannot use https://example.com/products?breed=dogs to match a URL to your Dog-themed widget config with Talkative's widget editor, and vice versa for cats. 

This is because Parameters can often can include sensitive information such as login credentials. E.g. https://example.com/myaccount?username=jeff&accountlevel=platinum&securetoken=123456789

However, if you would like to override this setting and instead ensure that Parameters are detected and used for your rules, then please use the following code snippet for a normal script installation (recommended):

Standard Code Snippet Below - Ignores Parameters 

<script>
import(`https://*.engage.app/api/ecs/v1/loader/1371f5fe-1828-4b5c-b106-c4d8a77f5997.js?path=${encodeURIComponent(window.location.origin+window.location.pathname)}&selectedVersion=${(new URLSearchParams(window.location.search)).get('ecsSelectedVersion') || ''}`)
</script>

Please ensure to include your correct region and uuid (highlighted in bold above).

Modified Code Snippet Below - Includes Parameters 

<script>
import(`https://*.engage.app/api/ecs/v1/loader/1371f5fe-1828-4b5c-b106-c4d8a77f5997.js?path=${encodeURIComponent(window.location.toString())}&selectedVersion=${(new URLSearchParams(window.location.search)).get('ecsSelectedVersion') || ''}`)
</script>

Please ensure to include your correct region and uuid (highlighted in bold above).

If you are using Google Tag Manager, you will need to edit the script below instead.

Standard Google Tag Manager Code Snippet Below - Ignores Parameters 

<script>

var script = document.createElement('script');
script.innerHTML = "import(`https://*.engage.app/api/ecs/v1/loader/1371f5fe-1828-4b5c-b106-c4d8a77f5997.js?path=${encodeURIComponent(window.location.origin+window.location.pathname)}&selectedVersion=${(new URLSearchParams(window.location.search)).get('ecsSelectedVersion') || ''}`)";
document.body.appendChild(script);

</script>

Please ensure to include your correct region and uuid (highlighted in bold above).

Modified Google Tag Manager Code Snippet Below - Includes Parameters 

<script>

var script = document.createElement('script');
script.innerHTML = "import(`https://*.engage.app/api/ecs/v1/loader/1371f5fe-1828-4b5c-b106-c4d8a77f5997.js?path=${encodeURIComponent(window.location.toString())}&selectedVersion=${(new URLSearchParams(window.location.search)).get('ecsSelectedVersion') || ''}`)";
document.body.appendChild(script);

</script>

2. Card Rules 

Card Rules can use query parameters to decide which widget to load. You do not need to modify your script for this (since it is decided client side). 

First, you need to ensure your widget is on version 0.43 or higher.

Go to Advanced and enable this config:

This will now support query strings in the URL rules specified at the Card level:


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article