Skip to content

Instantly share code, notes, and snippets.

View chavesm's full-sized avatar

Mark Chaves chavesm

View GitHub Profile
@chavesm
chavesm / crisp-ga-send-event-gtag.html
Last active March 5, 2021 15:04
Use the Crisp Chat JavaScript API to send an event to GA via MonsterInsights gtag version.
<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>
@chavesm
chavesm / 1029038-avada-forms-ids-readme.js
Last active March 6, 2021 13:35
This JavaScript function will add missing form IDs to Avada forms except for search forms.
/**
* Add missing form IDs for conversion tracking.
*/
(function(){
// Grab all the forms on the page.
const formElts = document.querySelectorAll("form");
// If no forms, bail.
if (!formElts.length) return;
@chavesm
chavesm / mi-cookie-notice-no-consent.js
Last active March 13, 2021 08:29
Disable Google Analytics tracking via MonsterInsights (gtag version) when cookie consent in Cookie Notice plugin is rejected.
@chavesm
chavesm / mi-cookie-banner-no-consent.js
Created March 13, 2021 09:09
Disable Google Analytics tracking via MonsterInsights (gtag version) when cookie consent in Cookie Banner plugin is rejected.
@chavesm
chavesm / chrome-dev-tools-snippets-README.md
Last active March 16, 2021 14:53
Find Links and Forms Using JavaScript and Chrome Dev Tools (snippets and console)
@chavesm
chavesm / monsterinsights_custom_add_ga4_tracking.php
Last active March 17, 2021 09:03
MonsterInsights Add GA4 Measurement ID for Dual Tracking (UA and GA4)
<?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. */
@chavesm
chavesm / add-data-vars-ga-to-popular-posts-link.js
Last active March 19, 2021 03:54
Add data-vars-ga link attributes to Popular Posts links
@chavesm
chavesm / mi-cookiebot-no-consent.js
Created March 23, 2021 08:26
Disable Google Analytics tracking via MonsterInsights (gtag version) when cookie consent in Cookiebot plugin is rejected.
@chavesm
chavesm / monsterinsights_eu_compliance_tracking_didomi.php
Created March 23, 2021 10:34
Use MonsterInsights filter hook to set Didomi Web API attributes to control tracking based on visitor consent.
<?php // This line is not needed for functions.php.
function monsterinsights_eu_compliance_tracking_didomi( $attributes ) {
$attributes['data-vendor'] = "didomi:google";
$attributes['type'] = "didomi/javascript";
return $attributes;
}
add_filter( 'monsterinsights_tracking_analytics_script_attributes', 'monsterinsights_eu_compliance_tracking_didomi' );
@chavesm
chavesm / help-scout-auto-populate-custom-url-field.js
Created March 24, 2021 18:18
Auto populate customer URL from Help Scout Custom Field
(function(rn) {
let customerURL;
const customerURLElt =
document.querySelector(`#ex-templateBody td.ex-mcnTextContent table:nth-child(${rn}) tbody tr:nth-child(2) td a`);
if (customerURLElt) {
customerURL = customerURLElt.innerText;
}