Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Inyecte el script hotjar en la página angular dentro del elemento principal

Quiero agregar condiciones para cargar este script en la etiqueta principal. Necesito verificar si la URL es de nuestro dominio en vivo, entonces solo se ejecuta de lo contrario, no. Simplemente podría agregar este script al encabezado si no hubiera un requisito de condición. ¿Cómo puedo inyectar este script en la etiqueta principal en angular?

Por ejemplo:

window.origin == 'https://www.stackoverflow.com' luego inyecte este script en la etiqueta principal, de lo contrario no.

 <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=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>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede manejar esto en uno de sus componentes, preferiblemente en app.component. Por supuesto, podría verificar la URL, pero sería más elegante tener algún indicador como enableHotjarTracking en su archivo environment.ts y configurarlo como verdadero solo para su entorno de producción.

Entonces podría llamarlo de la siguiente manera en su app.component.ts

 import { environment } from './environments/environment'; import { DOCUMENT } from '@angular/common'; ... // inject document wrapper constructor( @Inject(DOCUMENT) private document: Document, ){} ngAfterContentInit() { if(environment.enableHotjarTracking) { ((h, o, t, j, a, r) => { h.hj = h.hj || /* tslint:disable:only-arrow-functions */ function () { (h.hj.q = h.hj.q || []).push(arguments); }; h._hjSettings = { hjid: xxxx, hjsv: x }; 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 as any, this.document, 'https://static.hotjar.com/c/hotjar-', '.js?sv='); } }

También puede mantener su identificación de hotjar en el archivo de entorno.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!