Welcome Guest, Not a member yet? Register   Sign In
having a chat widget appear (or not!)
#1

I'd like to offer paying customers premium support. I have a support widget that I plan to use on a system called tawk.to. They advise to embed the following code on the page. 
<!--Start of Tawk.to Script-->

<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->


Now in my case I am adding the a few lines of HTML at the bottom of every page (see below). Can I just paste the above script onto that page and expect it to display? 
<h1>company</h1>

<p></p>
<a href="https://researchstudytoolkit.tawk.help/category/setting-up-the-research-credit-study-toolkit#company-tab" target="_blank">help on setting up the research study online</a>
<br>
<br>

can I just place the above script here?
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 07-20-2021, 05:51 PM by richb201.)

I managed to get the regular old chat widget working. Now I just need to be able to have that appear only for paying users. I created a flag in the session vars for it.  I then tried adding this code. Can I not wrap javascript within a php section? I need to use php to check if the user gets premium support or not. 

<?php
        if ($_SESSION['premium_support']==1)
          {
          <script type="text/javascript">
              var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
              (function(){
                  var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
                  s1.async=true;
                  s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
                  s1.charset='UTF-8';
                  s1.setAttribute('crossorigin','*');
                  s0.parentNode.insertBefore(s1,s0);
              })();
          </script>
          }

?>         

How can I accomplish this? 
<?
?>         
proof that an old dog can learn new tricks
Reply
#3

You need to load the script on startup or it will not load later, best bet would to add it to a div then hide it.
After that if they are a paying customer then show the hidden div.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

I used pusher.Io realtime service for notifications and chat communication
Pusher. Io has great service and clear documentation , eazy work with it

Pusher. Io offers free and perumin plans too
Enlightenment  Is  Freedom
Reply
#5

For what version of CodeIgniter are you searching this solution?
Reply
#6

You can accomplish this, but you can't just embed Javascript code directly in your PHP code.

Code:
<?php if ($_SESSION['premium_support']==1): ?>
<script type="text/javascript">
  var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
  (function(){
      var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
      s1.async=true;
      s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default';
      s1.charset='UTF-8';
      s1.setAttribute('crossorigin','*');
      s0.parentNode.insertBefore(s1,s0);
  })();
</script>
<?php endif; ?>

The only thing to make sure of is that the session variable 'premium_support' has a value.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB