Last active
January 23, 2024 16:40
-
-
Save Asikur22/71cf0e0f7aae768ce1afd27f69eaf4bc to your computer and use it in GitHub Desktop.
GA Scripts #GA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]); | |
jQuery(".et_pb_contact_form").each(function() { | |
var jqForm = jQuery(this); | |
var jsForm = this; | |
jqForm.submit(function(event) { | |
event.preventDefault(); | |
gtag('event', 'submit', { 'event_category': 'Contact Us Form Tracking', 'event_action': 'submit', 'event_label': 'Form Completed' } ); | |
setTimeout(function() { jsForm.submit(); }, 300); | |
}); | |
}); | |
// For analytics.js | |
<script> | |
jQuery( document ).ready(function($) { | |
jQuery('body').on('click', 'a[href^="tel:"]', function() { | |
var n = jQuery(this).attr('href').replace('tel:', ''); | |
ga('send', 'event', 'Phone Click Tracking', n, 'Click to Call', n); | |
}); | |
jQuery('body').on('click', 'a[href^="mailto:"]', function() { | |
var n = jQuery(this).attr('href').replace('mailto:', ''); | |
ga('send', 'event', 'Email Click Tracking', n, 'Click to Email', n); | |
}); | |
document.addEventListener('wpcf7mailsent', function(event) { | |
ga('send', 'event', 'Contact Form Tracking', 'submitted', 'Form Completed'); | |
}, false); | |
document.addEventListener('wpcf7mailsent', function() { | |
ga('send', 'event', 'Contact Form Tracking', 'submit', 'Form Submitted'); | |
}, false); | |
document.addEventListener('submit_success', function() { | |
ga('send', 'event', 'Elementor Form Tracking', 'submit', 'Form Submitted'); | |
}, false); | |
}); | |
</script> | |
// For gtag.js | |
<script> | |
jQuery( document ).ready(function($) { | |
jQuery('body').on('click', 'a[href^="tel:"]', function() { | |
var n = jQuery(this).attr('href').replace('tel:', ''); | |
gtag('event', 'click', { 'event_category': 'Phone Click Tracking', 'event_action': n, 'event_label': 'Click to Call', 'value': n } ); | |
}); | |
jQuery('body').on('click', 'a[href^="mailto:"]', function() { | |
var n = jQuery(this).attr('href').replace('mailto:', ''); | |
gtag('event', 'click', { 'event_category': 'Email Click Tracking', 'event_action': n, 'event_label': 'Click to Email', 'value': n } ); | |
}); | |
jQuery('.social_ico a').on('click', function() { | |
var n = jQuery(this).attr('href'); | |
gtag('event', 'click', { 'event_category': 'Social Links Tracking', 'event_action': n, 'event_label': 'Clicked ' + n } ); | |
}); | |
document.addEventListener('wpcf7mailsent', function() { | |
gtag('event', 'submit', { 'event_category': 'Contact Form Tracking', 'event_action': 'submit', 'event_label': 'Form Submitted' } ); | |
}, false); | |
document.addEventListener('submit_success', function() { | |
gtag('event', 'submit', { 'event_category': 'Elementor Form Tracking', 'event_action': 'submit', 'event_label': 'Form Submitted' } ); | |
}, false); | |
}); | |
</script> | |
<script> | |
document.addEventListener("DOMContentLoaded", function () { | |
[].forEach.call(document.querySelectorAll('a[href^="tel:"]'), function (el) { | |
el.addEventListener('click', function () { | |
var n = el.getAttribute('href').replace('tel:', ''); | |
ga('send', 'event', 'Phone Click Tracking', n, 'Click to Call', n); | |
}); | |
}); | |
[].forEach.call(document.querySelectorAll('a[href^="mailto:"]'), function (el) { | |
el.addEventListener('click', function () { | |
var n = el.getAttribute('href').replace('mailto:', ''); | |
ga('send', 'event', 'Email Click Tracking', n, 'Click to Email', n); | |
}); | |
}); | |
[].forEach.call(document.querySelectorAll('#comp-jxlmgdiaitemsContainer a'), function (el) { | |
el.addEventListener('click', function () { | |
var n = el.getAttribute('href'); | |
ga('send', 'event', 'Social Links Tracking', n, 'Click to Connect'); | |
}); | |
}); | |
document.addEventListener('wpcf7mailsent', function() { | |
gtag('event', 'submit', { 'event_category': 'Contact Form Tracking', 'event_action': 'submit', 'event_label': 'Form Submitted' } ); | |
}, false); | |
document.addEventListener('submit_success', function() { | |
gtag('event', 'submit', { 'event_category': 'Elementor Form Tracking', 'event_action': 'submit', 'event_label': 'Form Submitted' } ); | |
}, false); | |
}); | |
</script> | |
// For Shopify Site | |
<script> | |
ShopifyAnalytics.lib.ready(function(){ | |
[].forEach.call(document.querySelectorAll('.social-icons a'), function (el) { | |
el.addEventListener('click', function () { | |
var n = el.getAttribute('href').replace('tel:', ''); | |
ga('send', 'event', 'Social Links Tracking', n, document.referrer, {'nonInteraction': 1}); | |
}); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Global Site Tag (gtag.js). | |
if ('undefined' !== typeof gtag) { | |
gtag('event', 'contact_form_7', { | |
event_category: 'Contact Form 7', // eslint-disable-line camelcase | |
event_action: eventLabel, // eslint-disable-line camelcase | |
event_label: formLabel // eslint-disable-line camelcase | |
}); | |
} | |
// Google Tag Manager (gtm.js). | |
if ('undefined' !== typeof dataLayer) { | |
dataLayer.push({ | |
event: 'Contact Form 7', | |
event_action: 'Event Action', | |
event_label: 'Event Label' | |
}); | |
} | |
// Universal Google Analytics tracking code (analytics.js). | |
// Google Analytics Dashboard for WordpPress (GADWP). | |
if ('undefined' !== typeof ga) { | |
ga('send', 'event', 'Contact Form 7', eventLabel, formLabel); | |
} | |
// Classic Google Analytics default code. | |
if ('undefined' !== typeof _gaq) { | |
_gaq.push(['_trackEvent', 'Contact Form 7', eventLabel, formLabel]); | |
} | |
// Monster Insights. | |
if ('undefined' !== typeof __gaTracker) { | |
__gaTracker('send', 'event', 'Contact Form 7', eventLabel, formLabel); | |
} | |
/** See https://contactform7.com/dom-events/ */ | |
document.addEventListener('wpcf7invalid', function(event) { | |
}, false); | |
/** Spam: Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected */ | |
document.addEventListener('wpcf7spam', function(event) { | |
}, false); | |
/** Mail Sent: Fires when an Ajax form submission has completed successfully, and mail has been sent */ | |
document.addEventListener('wpcf7mailsent', function(event) { | |
}, false); | |
/** Mail Failed: Fires when an Ajax form submission has completed successfully, but it has failed in sending mail */ | |
document.addEventListener('wpcf7mailfailed', function(event) { | |
}, false); | |
/** Submit: Fires when an Ajax form submission has completed successfully, regardless of other incidents */ | |
document.addEventListener('wpcf7submit', function(event) { | |
}, false); | |
document.addEventListener( 'wpcf7mailsent', function( event ) { | |
if ( '123' == event.detail.contactFormId ) { | |
// do something productive | |
} | |
}, false ); | |
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]); | |
gtag('event', <action>, { | |
'event_category': <category>, | |
'event_label': <label>, | |
'value': <value> | |
}); | |
jQuery( document ).ready(function($) { | |
jQuery('body').on('click', 'a[href^="tel:"]', function() { | |
var n = jQuery(this).attr('href').replace('tel:', ''); | |
ga('send', 'event', 'Phone Call Tracking', 'Click to Call', n, 0); | |
}); | |
jQuery('body').on('click', 'a[href^="mailto:"]', function() { | |
var n = jQuery(this).attr('href').replace('mailto:', ''); | |
ga('send', 'event', 'Click to Email', n, 0); | |
}); | |
document.addEventListener('wpcf7submit', function(event) { | |
ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Form Completed'}); | |
}, false); | |
} | |
jQuery('.dmCall').on('click', function() { | |
var n = jQuery(this).find('.phoneNumHolder').text(); | |
ga('send', 'event', 'Phone Call Tracking', 'Click to Call', n, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment