Clientside Analytics for Sitecore
That being said, being able to trigger a goal, page event or even an interaction client side is a common need and very useful. Unfortunently, Sitecore doesn’t have a client side API for triggering these things, and there are many articles on how to build your own custom endpoints to track things.
I’ve even built a test harness html page that shows you how to use the API, which I demonstrate in this video:
So what can you do with this API/Library?
Get Tracker - Fetches details about current visitor and events/goals triggered for a page request.
Identify Contact - Identify the contact as a known contact based on a unique identifier and identifier source.
Track Goal - Trigger a Goal configured in Sitecore by Name or Id
Track Page Event - Trigger a Page Event configured in Sitecore by Name or Id
Track Custom Event - Trigger a Page Event with additional details (think dimension or metric)
Track Outcome - Trigger an Outcome with a monetary Value.
Trigger Campaign - Trigger a campaign configured in Sitecore by Name or Id.
End the Session - End the Session and immediately flush to xDB (Useful for testing)
Github project is located here. There is an initial release which has been tested on Sitecore 9.1. Let me know what you think, and feel free to contribue.