Skip to content

Instantly share code, notes, and snippets.

View chavesm's full-sized avatar

Mark Chaves chavesm

View GitHub Profile
@chavesm
chavesm / 1004596-mi-set-custom-dimension-README.md
Last active February 5, 2021 10:25
Set a Google Analytics Custom Dimension using a MonsterInsights PHP Filter
@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-affiliate-tracking-with-pretty-links-readme.md
Last active July 9, 2021 16:18
How to Set Up Affiliate Link Tracking in MonsterInsights using the Pretty Links Plugin
@chavesm
chavesm / mi-email-filter-hooks.php
Created December 22, 2020 12:24
PHP filter hooks to supply a custom from email address and name for MonsterInsights email summary reports.
<?php
/** MonsterInsights Email Hooks */
// Sender email address filter hook.
function my_custom_sender_email_address( $original_sender_email_address ) {
return 'YOURSENDEREMAILADDRESS';
}
add_filter( 'monsterinsights_email_from_address', 'my_custom_sender_email_address' );
// Sender name filter hook.
@chavesm
chavesm / mi-plugin-theme-conflict-readme.md
Last active January 30, 2021 20:27
How to debug WordPress plugin and theme conflicts.

How to Troubleshoot a Possible Plugin or Theme Conflict with MonsterInsights

Debugging a plugin or theme conflict should be done on a staging site if possible.

While you're debugging (depending on the type of error), you should have the JavaScript console or PHP error log in view in real-time.


1) Make a full backup of your site.

@chavesm
chavesm / how-to-do-a-realtime-test-in-mi-README.md
Last active April 29, 2021 08:51
How to do a Real-time Test in MonsterInsights

How to Test Your Google Analytics in Real-time

These are the steps for testing if your Google Analytics is working with and without MonsterInsights.


MonsterInsights Real-Time Report

A MonsterInsights premium plan is required.

@chavesm
chavesm / how-to-track-login-events-gtm-README.md
Last active April 10, 2021 09:56
How to Track Login Events with Google Tag Manager

How to Track Login Events with Google Tag Manager

The Trigger

  1. Create a Form Submission trigger. Name it something like Login.

  2. Select trigger fires on Some Forms.

  3. Add a Page URL condition that contains some text that's contained in the URL of your login form.

<?php // Ignore this line when copying/pasting this code to your child theme's functions.php file.
/**
* This example sets custom dimension #9 to be the WordPress
* post ID of the page/post being visited.
*
* This is compatible with MonsterInsights gtag code. This filter supercedes
* the monsterinsights_frontend_tracking_options_analytics_before_pageview
* filter.
*
@chavesm
chavesm / codeless_remove_type_attr.php
Created February 24, 2021 07:16
WordPress filter hook that tries to remove unnecessary "text/javascript" and "text/css" from HTML source. Add to Child theme's functions.php.
<?php
/** Try to Remove Unnecessary "text/javascript" and "text/css" */
function codeless_remove_type_attr($tag, $handle) {
return preg_replace( "/type=['\"]text\/(javascript|css)['\"]/", '', $tag );
}
add_filter('style_loader_tag', 'codeless_remove_type_attr', 10, 2);
add_filter('script_loader_tag', 'codeless_remove_type_attr', 10, 2);
@chavesm
chavesm / remove_type_attr_1148073.php
Last active June 29, 2021 11:42
Remove unnecessary "type" attribute from MI script code to keep HTML validators happy. Second file adds async attribute to external gtag script.
<?php // Ignore this line if copying to child theme's functions.php
/** Remove the unnecessary "type" attribute from MI script code by leaving it out of the filter. */
function remove_type_attr_1148073() {
return array(
'data-cfasync' => 'false' // Ask CloudFlare Rocket Loader not to execute.
);
}
add_filter( 'monsterinsights_tracking_analytics_script_attributes', 'remove_type_attr_1148073' );