How to assign different properties in different urls?

Created on 30 August 2023, about 1 year ago
Updated 18 September 2023, about 1 year ago

Problem/Motivation

Our use case is we have multiple properties, where we want the users from different regions can open chat to their specific property. Is there a way to implement this (javascript, etc)?

πŸ’¬ Support request
Status

Closed: works as designed

Version

3.0

Component

Miscellaneous

Created by

πŸ‡²πŸ‡ΎMalaysia akmalfikri

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @akmalfikri
  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    It should be possible by using preprocess functions for the

        'tawk_to' => [
          'variables' => [
            'items' => [],
          ],
        ],
    
    

    or changing directly in the https://git.drupalcode.org/project/tawk_to/-/blob/3.0.x/templates/tawk-t...

  • πŸ‡²πŸ‡ΎMalaysia akmalfikri

    I'm not very good in javascript, but here I go.

    I tried to use onBeforeLoad instead :

    window.Tawk_API.onBeforeLoad = function(){
        $(s1).src = "https://embed.tawk.to/"+ $(propertyid) + "/default";
    };
    

    but doesn't seem to work.

  • πŸ‡ΊπŸ‡¦Ukraine andriy khomych

    Well, it isn't PHP,I suggest to create in your theme twig template tawk-to.html.twig and inject it here:

    <!--Start of Tawk.to Script-->
    <script type="text/javascript">
      var Tawk_API=Tawk_API||{};
      Tawk_API.visitor = {
        name: "{{ items.user_name }}",
        email: "{{ items.user_email }}",
      };
      var $_Tawk_LoadStart = new Date();
      (function () {
        var s1 = document.createElement("script"), s0 = document.getElementsByTagName("script")[0];
        s1.async = true;
        {% autoescape false %}
        s1.src = "{{ items.embed_url }}/{{ items.page_id }}/{{ items.widget_id }}";
        {% endautoescape %}
        s1.charset = "UTF-8";
        s1.setAttribute("crossorigin", "*");
        s0.parentNode.insertBefore(s1, s0);
      })();
    </script>
    <!--End of Tawk.to Script-->
    

    and replace, adjust part :

     {% autoescape false %}
        s1.src = "{{ items.embed_url }}/{{ items.page_id }}/{{ items.widget_id }}";
        {% endautoescape %}
  • πŸ‡²πŸ‡ΎMalaysia akmalfikri

    Thank you @Andriy Khomych! That works!

    Now my issue is 404 for some of the properties.

  • Status changed to Closed: works as designed about 1 year ago
Production build 0.71.5 2024