GTM Tracking is an open source library supporting an integration with Google Tag Manager (GTM) using a Data Layer in order to capture and report on the users' activity on a website.
Key classes implementing the core functionality are
GTM
class extends the standard window.dataLayer.push() method;BaseElement
class defines a basic element with the commin properties and methods;CtaEventTracker
class implements an event handler for tracking by data attributes.
Once you have integrated this library into your solution, you can simply specify the required data attributes to the elemnets you want to track. For example, for a button element you can specify the data attributes as follows:
<button track-category="Your tracking category" track-label="Your tracking label" />
Hope you found this library helpful, your contributions and suggestions will be very much appreciated. Please submit a pull request.
The GTM Tracking library is released under the MIT license what means that you can modify and use it how you want even for commercial use. Please give it a star if you like it and your experience was positive.