Search code examples
hotjar

How to tag hotjar videos automatically using Javascript


I'm trying to tag our Hotjar recordings automatically from within google optimize so we can more easily identify A or B users. The problem is that I can't find anywhere that explains how to do this, the official documentation explains that you can do this, just not how to do it, it only goes on to explain how to do it manually.

How do you use javascript to automatically tag a Hotjar recording?


Solution

  • From the official documentation:

    Recordings can be automatically tagged using a JavaScript code snippet. If your visitor visits any page which runs this JavaScript code, their Recording will be saved with the tag/s you set. To tag a Recording, add this JavaScript code:

    hj('tagRecording', ['tag1', 'tag2']);
    

    Doing so will cause all Recordings of visitors who pass through this page to include the two tags "tag1" and "tag2".


    Important

    If there is a chance that the code will be run before the Hotjar script has loaded, you must add this line of code just before.

    window.hj=window.hj||function(){(hj.q=hj.q||[]).push(arguments)};