Jump to content

Integrating Hotjar Tracking (JS) into the head of WHMCS


Recommended Posts

Hi,

How do I go about implementing Hotjar's javascript into WHMCS? I'm assuming I cannot just add it into the header.tpl of my theme (Hexa) as it breaks the theme. Here's the code:

 


  <!-- Hotjar Tracking Code for https://billing.inteldigital.co.uk -->
    <script>
        (function(h,o,t,j,a,r){
            h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
            h._hjSettings={hjid:,hjsv:};
            a.appendChild(r);
        })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
    </script>

I've tried using {literal} too, which parses the theme, but it doesn't call the JS. Assuming this is what it's purpose is, so what's the solution?

Link to comment
Share on other sites

generally, to pass this into a header, I would use a hook...

 

<?php

/**
* Hotjar Tracking Code
* @author brian!
*/

add_hook('ClientAreaHeadOutput', 1, function($vars) {
    
	return <<<HTML
  <!-- Hotjar Tracking Code for https://billing.inteldigital.co.uk -->
    <script>
        (function(h,o,t,j,a,r){
            h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
            h._hjSettings={hjid:,hjsv:};
            a.appendChild(r);
        })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
    </script>
HTML;

});

if you put it into the header template directly, Smarty will have an issue with the brackets and you might need {literal} around them, not the whole code... but do it as a hook and you bypass Smarty and it should work fine on Six (I can see it in the browser source).... now whether it would work on Hexa I cannot say, but if you find it works on Six, but not Hexa, then it's probably a question for it's developer.

 

Link to comment
Share on other sites

1 minute ago, inteldigital said:

Thanks for this response. I managed to pop it into header.tpl and using literal tags it shows in the browser source, but does not get seen on the Hotjar dashboard (it's as if it doesn't exist). Why is this?

did you try it as a hook ?

Link to comment
Share on other sites

  • 2 months later...
On 6/4/2018 at 12:54 PM, brian! said:

generally, to pass this into a header, I would use a hook...

I'm using the hook as described, now the Hotjar code doesn't break the template page (raw copy of the six template), but - nothing happens with tracking. I can't get the Hotjar code verified at their admin panel. Now, wondering if this hook only fires up when the client is actually logged into client area?

Link to comment
Share on other sites

49 minutes ago, onliner said:

I'm using the hook as described, now the Hotjar code doesn't break the template page (raw copy of the six template), but - nothing happens with tracking. I can't get the Hotjar code verified at their admin panel. Now, wondering if this hook only fires up when the client is actually logged into client area?

+ I can actually see the Hotjar code in the page source as-well...

check that your Hotjar code is correct - not the hook that adds it, but the actual code that Hotjar want you to use - because when I look at the page below, their example code looks different to the code i've added in the above hook.

https://help.hotjar.com/hc/en-us/articles/115009499088-The-Hotjar-Tracking-Code

 

Link to comment
Share on other sites

Just now, inteldigital said:

I didn't use the hook. There was no need in the end, it just took a while for the code to be seen by Hotjar for some reason. Works just fine now! @onliner

Whatever I do, the code break the layout of the whmcs template. Do you mind sharing the code format you've been using, please?

Link to comment
Share on other sites

  {literal}
<script>
    (function(h,o,t,j,a,r){
        h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
        h._hjSettings={hjid:11111,hjsv:6};
        a=o.getElementsByTagName('head')[0];
        r=o.createElement('script');r.async=1;
        r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
        a.appendChild(r);
    })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>
  {/literal}

@onliner

Link to comment
Share on other sites

1 minute ago, onliner said:

@inteldigital 

I'm using the same code, the page layout is not affected now. But I can't get Hotjar to verify it though.

Yep, give it some time (24 hours). I actually contacted Hotjar when the same thing happened to me, but they said they could see it working and after a day or so I could see it in my panel too.

Link to comment
Share on other sites

6 minutes ago, inteldigital said:

Yep, give it some time (24 hours). I actually contacted Hotjar when the same thing happened to me, but they said they could see it working and after a day or so I could see it in my panel too.

Wonderful! Ok, let's hope so. Thanks.

Link to comment
Share on other sites

  • 1 year later...
  • 10 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated