Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
Getting data from a dynamic object in an event of my Datalayer

I'm requesting your help, I have trouble to catch data from a specific event in my datalayer.

So, I have a pop-up survey on my website. I'm pushing the answers in my GTM datalayer as you can see on the screenshot below : Basic Answer without filling textarea fields

In the survey, there are 2 textarea who doesn't appears in the datalayer if the user don't fill them. If the user fill the text area, you have the following result in the datalayer: Basic answer with textarea being filled in

A user can fill 0, 1 or 2 textareas.

Note that the object userData.data doesn't have the same length according if the user is filling textareas or not.

My goal is to send the data I'm receving in the UserData.data object to Google Analytics.

In GA I want to receive data as following example:

  • eventCategory: Campaign + eventLabel we can see on the screenshot
  • eventAction: Key data from userData.data (ex: First_Time_On_Site or Purchasing_Factor or Type_content, etc...)
  • eventLabel: Value data from userData.data (ex if eventAction = First_Time_On_Site I want to receive the answer of the question so here "Yes" or "No" according of what we get from the datalayer).

I'm using the following code to get the data, but I'm not getting what I want.

      // When a campaign is started listen for answers, otherwise we're done
      if (action != "Campaign:Open") {
        return;
      }

      window.addEventListener("message", function (event) {
        // Listen to messages from the Usabilla Cloudfront domain
        if (!/d6tizftlrpuof\.cloudfront\.net/.test(event.origin)) {
          return;
        }

        try {
          var data = JSON.parse(event.data);
          // On the final page

          // if data type is not STRING then join and make a string before sending to GA
          if (data.type === "pageSwitch" && data.end) {
            for (var key in data.data) {
              if (typeof data.data[key] !== "string") {
                data.data[key] = data.data[key].join(", ");
              }

              ga(
                "ga_trackername" + ".send",
                "event",
                "Usabilla Campaign - " + label, // event category
                key, // event action
                data.data[key] // event label
              );
            }
          }
        } catch (e) {
          // Ignore errors, usually JSON decode problems
        }
      });
    }
  );
  // End Sending event to GA

At the moment I'm receiving the data from the Action/Category/Label present in my datalayer event. My goal is to receive the data from the object userData.data. Does anyone have any idea to update this code to send the correct data?

Thanks a lot for your help here.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda