https://developers.google.com/web/tools/chrome-devtools/javascript/snippets
This file contains hidden or 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
<script> | |
// Adjust the bounce rate for GA. | |
setTimeout(function(){__gtagTracker('event', 'page visit 20 seconds or more', { | |
'event_category' : 'adjusted bounce rate', | |
})},20000); | |
</script> | |
<!-- Add to head section of page. --> |
This file contains hidden or 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
<script> | |
// Send an event via gtag. | |
__gtagTracker('event', 'Test Event', { | |
'event_category' : 'test_event', | |
'event_action' : 'test_action', | |
'event_label' : 'This is a test event.' | |
}); | |
</script> | |
<!-- Add to head section of page using proper enqueue | |
techniques or a plugin like Insert Headers and Footers. --> |
This file contains hidden or 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
<?php | |
function monsterinsights_custom_add_ga4_tracking() { | |
echo "__gtagTracker( 'config', 'G-12345678' );"; // Change the measurement ID to yours. | |
} | |
add_action( 'monsterinsights_frontend_tracking_gtag_after_pageview', 'monsterinsights_custom_add_ga4_tracking', 15 ); | |
/** Add to child theme's functions.php file. */ |
This file contains hidden or 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
<script> | |
// Send an Crisp Chat event via gtag. | |
$crisp.push(["on", "chat:initiated", function() { | |
__gtagTracker('event', 'Test Event', { | |
'event_category' : 'test_event', | |
'event_action' : 'test_action', | |
'event_label' : 'This is a test event.' | |
}); | |
}]); | |
</script> |
This file contains hidden or 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
(function () { | |
const searchForm = document.getElementById("search_form_map1881"); | |
const searchInput = document.getElementById("cspm_address_map1881"); | |
function sendEvent(event) { | |
// DEBUG | |
console.log(`Search city entered for searchForm is: ${searchInput.value}`); | |
// GA code goes here. Below is an example using gtag.js API | |
// via MonsterInsights. |
This file contains hidden or 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
/** Add data-vars-ga for MI Popular Posts Links */ | |
setTimeout(function() { | |
//const clStyle = "font-size: 20px; color: limegreen"; | |
const qSels = [ | |
".monsterinsights-inline-popular-posts-post a", | |
".monsterinsights-widget-popular-posts-list a", | |
".monsterinsights-products-popular-posts-list a", | |
]; | |
function addDataVarsGA(pps) { | |
pps.forEach((elem) => { |