How to remove hotjar scripts in wordpress

2.6k Views Asked by At

In a website that did not have the hotjar plugin activated, I deleted the hotjar plugin (could have been the hotjar for wordpress plugin).

Seemed okay until I noticed that hotjar script was still loaded. I looked everywhere to find where and what adds the script and other bits but I can't find it in the codes.

Here are the files loading:

304 GET static.hotjar.com   hotjar-1716472.js?sv=7  script  js  mis en cache    3,26 Ko
304 GET script.hotjar.com   modules.5366b7bc7306ec7916c3.js script  js  mis en cache    0 o
    GET vars.hotjar.com box-469cf41adb11dc78be68c1ae7f9457a4.html   subdocument html    851 o (en compétition)  2,01 Ko
200 OPTIONS in.hotjar.com   visit-data?sv=7 xhr octet-stream    362 o   0 o
200 POST    in.hotjar.com   visit-data?sv=7 xhr json    486 o   169 o

Anyone has a clue about how to find out the code that adds the scripts? The below script is the first to be added after the head tag. No, it is not in the header.php and I searched the files for hotjar and h.hj and found nothing.

<script type="text/javascript" async="" src="https://static.hotjar.com/c/hotjar-1716472.js?sv=7"></script>

Any clue would be appreciated. Thanks!

2

There are 2 best solutions below

1
On

It could be coming from a few places:

The theme or a plugin

The script-tag could be coded into a template file, called via wp_enqueque_script, or added via another means, by echoing in a callback on the wp_footer hook.

Open the wp-content/themes and wp-content/plugins folders & do a global-search for relevant terms, static.hotjar would be a good starting point. If you find the code you can comment it out or remove it - but be careful that it's not in a file which could be overwritten by another developer or an update.

The database

Many WordPress sites have coded saved to a custom-field which is only loaded output on the site by wordpress hooks & filters. The snippet could part of a text-field which has been saved and is then being output without having a corelation between the script tag and the site-code in any way.

in this case, past experience is your best friend. The more places you can think of to look, the better. You'll likely be able to find the cause by searching around wp-admin for a bit. Generally, a plugin or theme will have some means of adding custom code to the site. It might not even look like a hotjar-code, it could be checkbox or be something more discrete. It can also help to search the database itself for the script-tags / string s you're looking for.

that kind of covers it

  • javascript can add script-tags to the site after the page has loaded.
  • good places to look for custom scripts being added are under the Appearance tab (as there's sometimes theme-options pages there)
  • it might even be caching too, have you cleared the cache on the site? do you maybe have static html cached?
0
On

I had the same issue, and it was somehow related to Google Tag Manager in my case.

The script was not present in the initial source code, but only later in the final, rendered version of that page. So I suspected that the script was injected afterward in a way or another. I checked the theme, the plugins, and couldn't find anything that could have placed that script in the header section.

Anyway, Google Tag Manager can insert scripts, so I replaced the Google Tag Manager tracking code with a Google Analytics code, and that hotjar script disappeared. I am not a Google Tag Manager specialist, so maybe there is a better way to manage this issue.