🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Add custom event tracking section to Google Tag Manager guide
Bill Yangf237de24f3e6
diff --git a/docs-v2/content/docs/guides/google-tag-manager.mdx b/docs-v2/content/docs/guides/google-tag-manager.mdxindex 7987753c7..e38444830 100644--- a/docs-v2/content/docs/guides/google-tag-manager.mdx+++ b/docs-v2/content/docs/guides/google-tag-manager.mdx@@ -71,4 +71,102 @@ Assign a trigger to determine when the tag should fire. For instance, to load RySave your changes and publish the container to make the tag active on your website.</Step>-</Steps>\ No newline at end of file+</Steps>++## Custom Event Tracking++Once Rybbit is loaded through GTM, you can track custom events using JavaScript. Since GTM already handles the script loading, you can directly call the Rybbit tracking functions.++### Method 1: Direct JavaScript in GTM++You can create additional Custom HTML tags in GTM to track specific events:++```html+<script>+ // Track a custom event when this tag fires+ if (typeof window.rybbit !== 'undefined') {+ window.rybbit.event('gtm_custom_event', {+ event_category: 'engagement',+ event_label: 'button_click',+ value: 1+ });+ }+</script>+```++### Method 2: Track Events from Your Website Code++Once Rybbit is loaded via GTM, you can track events directly from your website's JavaScript:++```javascript+// Example: Track button clicks+document.addEventListener('DOMContentLoaded', function() {+ const ctaButton = document.getElementById('cta-button');+ if (ctaButton) {+ ctaButton.addEventListener('click', function() {+ if (typeof window.rybbit !== 'undefined') {+ window.rybbit.event('cta_clicked', {+ button_text: ctaButton.textContent,+ page_path: window.location.pathname,+ timestamp: new Date().toISOString()+ });+ }+ });+ }+});+```++### Method 3: Using GTM Variables and Triggers++You can leverage GTM's built-in variables and triggers to send custom events to Rybbit:++1. Create a new **Custom HTML** tag+2. Use GTM variables in your tracking code:++```html+<script>+ if (typeof window.rybbit !== 'undefined') {+ window.rybbit.event('{{Event}}', {+ page: '{{Page URL}}',+ referrer: '{{Referrer}}',+ click_text: '{{Click Text}}',+ click_url: '{{Click URL}}'+ });+ }+</script>+```++3. Set up triggers for specific interactions (e.g., form submissions, scroll depth, video plays)++### Common Event Examples++```javascript+// Form submission+window.rybbit.event('form_submitted', {+ form_id: 'contact-form',+ form_name: 'Contact Us'+});++// E-commerce tracking+window.rybbit.event('add_to_cart', {+ product_id: '12345',+ product_name: 'Example Product',+ price: 29.99,+ quantity: 1+});++// Video engagement+window.rybbit.event('video_played', {+ video_title: 'Product Demo',+ duration: 120,+ percent_watched: 75+});++// Download tracking+window.rybbit.event('file_downloaded', {+ file_name: 'whitepaper.pdf',+ file_type: 'pdf',+ file_size: '2.5MB'+});+```+