function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mark Stewart 13Mark Stewart 13 

Lightning Component to Track User Activity

Hi, I'm fairly new to SF and could use a little help pointing me in the right direction.

I've been tasked with creating a Lightning component that can be placed on any page in SF that will track who the user is, what form factor they're using, which page they're visiting, and optionally, a record ID if the page they're viewing has one (e.g. Contacts, etc.).

I'm familiar with LWC, but this won't have a UI, so I'm not sure where to start. The goal is to have a component that can be added to most pages where we want to track this information.

Thank you!
LuisMRochaLuisMRocha
Hi Mark,

Not sure what the end goal of this would be,

If they are trying to track items changing inside the salesforce org and maybe conduct auditing, you can try https://help.salesforce.com/articleView?id=security_overview_auditing.htm&type=5 some salesforce auditing.

If this is for example communities, I have had clients used google analytics to keep track of this. 

If these don't match your needs, you could create a component, and place it on pages, that init will create a record based on the logged user, stamp the url, and the recordId, but just imagine the number of records that will be created for this, and overall would this provide any meaningful information? Who would use this? How would searching go. I can't think of how this would be meaningful, I would say I would push back and possible go with one of the above two options. but with the context, I have I'm not sure. 
Laura BuonaiutoLaura Buonaiuto
I too am tasked with creating LWC to track user and (knowledge article) page view with date accessed to enhance Knowledge reporting; currently only total views are available and teh viewstat object is accessbile by API (so can't build a flow). Did anyone have any success at a page/user tracker component yet?
Muralikrishna PolimaraMuralikrishna Polimara
Did you try lightning:backgroundUtilityItem or import Id from '@salesforce/user/Id'?