I need to use hotjar for work, but i have some difficulties to set it up. The project is an ember project, and i have found this project to integrate hotjar : https://github.com/byrnedo/ember-hotjar
In this github page, it says : "in routes and controller you will have _hj.push available", but i can't manage to make it work and i can't find any information about how to set it up.
I added this in config/environment.js :
hotjar: {
id: my-id
},
And in a route, if i do this :
console.log(this.get('_hj'))
I get this result in the console :
ƒ () {
(window.hj.q = window.hj.q || []).push(arguments);
}
Meaning that hotjar is successfully installed, but when i'm trying to something like :
this.get('_hj').push('trigger', 'hello_world');
An error appears saying :
Uncaught TypeError: this.get(...).push is not a function
Does anyone know how to make it work or if i'm making something wrong ?
Is a result of you attempting to call
.pushon a function. As in, from yourconsole.log, we can see thatthis.get('_hj')is a function, and you attempted to call.pushon it. You'd get the same error if you tried:Anyway, let's get to the bottom of it. The addon has provided an initializer ember-hotjar that invokes:
Whatever
hotjar/mainexports is used to createh. This is registered in the dependency injection container for ember with the keyhotjar:mainas a shared object (iehotjar:mainholds a reference to an already instantiated object and not a factory). Then, because of theinject, all routes and all controllers are getting access to said object viathis._hj. Please see registration or the injections section of the guides for more information.So now, we need to investigate the main.js function that is exporting
hjthis is assigning
window.hj || function(){(window.hj.q=window.hj.q||[]).push(arguments)};to bothhjandwindow.hj, which ultimately means that in your controller,this._hj===function(){(window.hj.q=window.hj.q||[]).push(arguments)};So having seen all of that, I'm not really sure what you're expecting
pushto do. I think you may just wantthis._hj('trigger', 'hello_world')? Best of luck