Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
Google analytics track multiple custom variables

I'm tring to use google analytics to monitor activities on my laravel site, as you can see i managed to record the events by $user_name witch is great however how to i associate this user name with another variable for example $project_id so i can see data for each user and on each different project.

enter image description here

any idea how i can achieve this? here is my code:

<script>
$(document).ready(function(){
$(document).mousemove(function(){

  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-9YXX', {
  'custom_map': {'dimension<Index>': 'user_id'}
});

gtag('event', 'user_name', {'user_id': '{!!$user_name!!}'});

});

});

</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're calling the gtag directly from your codebase. This will inevitably increase your technical debt as well as clutter your code. It's better conducted directly from GTM.

Also, you're mixing up things... Events are supposed to represent certain actions or states. So the idea is to generate events on key activities and then fill them with data you need to pass. You do it differently: you generate an event whenever you need to pass data, so now your events are pretty much meaningless, you only use them as containers for dimensions. That will be a problem later on.

Another issue there is... are you sending an event on every mousemove? Just to indicate user id? There are these things in GA4 called user-level dimensions/properties. You should look at them and set them with pageviews rather than wasting events and cluttering your analytics and your users' network traffic.

Now finally, we've got to your question. You can send several properties with your events. You can see that the last argument of your gtag() call is an object. Well, use it:

gtag('event', 'user_name', {
    'user_id': '{!!$user_name!!}', 
    'project_id': '{!!$project_id!!}'
});

It's odd it didn't occur to you to try it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda