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

132
Views
How to send EVENTS in addition to pageviews using a Java Script GTM tag which is tracking Individual Logged in Users using Google Analytics?

I have used a JavaScript tag which is tracking Individual Logged in Users using Google Analytics. It has a statement "ga('send', 'pageview');", which results in showing the pages a particular user has viewed, in user explorer of Google Analytics. I want to send events (I have already created in GTM) along with pageviews with reference to User-ID i.e., shKey in my case.

Here is the code in my JS tag;

 <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-xxxxxxxxx-x' , 'auto');
    ga('set', 'userId', arguments.shKey);
    ga('set', 'dimension1', arguments.fname);
    ga('set', 'dimension2', arguments.type);
    ga('send', 'pageview'); 
    ga('send', 'event');
    </script>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

  1. Your ga('send', 'event') has a wrong signature. Events require category and action. So your event should look something like: ga('send', 'event', 'category', 'action', 'label');
  2. You're doing it strategically wrong. You're solving through JS what is supposed to be solved via GTM UI. In short term, it may seem easier and more elegant to do it in JS. In long term, however, it makes GTM obsolete and increases your technical debt, so the implementation becomes really difficult to maintain.
about 4 years ago · Juan Pablo Isaza Report

0

You have 2 issues: your code won't send an event (you're missing parameters), and you need to address PII (see further below)

This is how you send an event programmatically:
https://developers.google.com/analytics/devguides/collection/analyticsjs/events

ga('send', 'event', 'My Category', 'My Action', 'My Label');

However if you're using GTM, you might want to look into how to handle events with GTM:
https://developers.google.com/tag-manager/devguide

// You need to configure GTM UI to handle below event as desired
dataLayer.push({'event': 'event_name'});

Regarding PII, this is the authoritative answer from Google:
https://support.google.com/analytics/answer/6366371?hl=en

Google policies mandate that no data be passed to Google that Google could use or recognize as personally identifiable information (PII). PII includes, but is not limited to, information such as email addresses, personal mobile numbers, and social security numbers

If you want to use PII, it must be encrypted before being sent, from same link as above:

You can send Google Analytics an encrypted identifier or custom dimension that is based on PII, as long as you use the proper encryption level. Google has a minimum hashing requirement of SHA256

On top of that there might be additional legal restrictions depending on the jurisdiction you and your customers are in (eg in Europe you would have GDPR).

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!