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

153
Views
Error de análisis en la variable javascript personalizada GTM

¿Cómo puedo crear una nueva variable basada en 2 variables actuales separadas? La condición principal es verificar la existencia de una matriz o un selector de widgets y luego devolver su valor:

 function() { var array = Array.prototype.slice.apply(document.querySelectorAll("div.widget-message.active.active-target a")); var length = array.length; var x = array.map(function(cn, index) { var nameId = cn.href.split("?")[0].split("/").slice(-1)[0].replace("-", " "); var urlParams = {{cjs - utility - url params}}(cn.href); var name = urlParams.promo_name; var creative = urlParams.promo_content; return { "name": "Widget - Personal - " + name, "id": "Widget - Personal - " + nameId + "-" + index, "position": "" + (index + 1) + "/" + length, "creative" : creative, "metric3": 1 } }); return { 'ecommerce': { 'promoView': { 'promotions': x } } } }

y el segundo es

 function() { var array = document.querySelector('[class="btn-new btn-fullwidth popup-trigger"]'); return { 'ecommerce': { 'promoView': { "name": "Widget - Personal - " + array.dataset.targetId } }}; }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La combinación de ambas funciones se puede hacer comprobando array.length en el resultado del primer selector.

 function() { var array = Array.prototype.slice.apply(document.querySelectorAll("div.widget-message.active.active-target a")); var x = array.map(function(cn, index) { var nameId = cn.href.split("?")[0].split("/").slice(-1)[0].replace("-", " "); var urlParams = {{cjs - utility - url params}}(cn.href); return { "name": "Widget - Personal - " + urlParams.promo_name, "id": "Widget - Personal - " + nameId + "-" + index, "position": "" + (index + 1) + "/" + array.length, "creative" : urlParams.promo_content, "metric3": 1 } }); if (array.length > 0) { return { 'ecommerce': { 'promoView': { 'promotions': x } } } } array = document.querySelector('[class="btn-new btn-fullwidth popup-trigger"]'); return { 'ecommerce': { 'promoView': { "name": "Widget - Personal - " + array.dataset.targetId } } }; }

Ver comprobación de array.length > 0 . Si se encuentra ese selector, devolverá las promociones usando x . De lo contrario, el código continúa y encuentra el otro selector.

about 4 years ago · Santiago Trujillo 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!