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

85
Views
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 answers
Answer question

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 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!