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>
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).