Skip to content

Instantly share code, notes, and snippets.

View chavesm's full-sized avatar

Mark Chaves chavesm

View GitHub Profile
@chavesm
chavesm / simple-form-conversion-example.html
Last active September 17, 2020 10:16
Manually send a conversion hit to GA when a submit button is clicked on a form.
<form
action="http://caughtmyeye.epizy.com/simple-form/"
id="simple-test-form"
method="post"
data-avia-form-id="1"
data-avia-redirect=""
_lpchecked="1"
>
<fieldset>
<h3>Simple Test Form</h3>
@chavesm
chavesm / ga-custem-event-tracking.html
Last active September 19, 2020 11:48
Google Analytics Custom Event Tracking for MonsterInsights
<p>
Go to my
<a
href="http://caughtmyeye.epizy.com/link-tracking/"
data-vars-ga-category="internal-link"
data-vars-ga-action="http://caughtmyeye.epizy.com/"
data-vars-ga-label="http://caughtmyeye.epizy.com/link-tracking/">
link tracking
</a>
page.
@chavesm
chavesm / 961756-popupally-form-index.html
Last active October 2, 2020 22:17
Google Analytics Tracking Example for a Mock PopupAlly Optin Form
<~-- link href="https://cdn.jsdelivr.net/gh/marklchaves/cme-styles@1.0.0/dist/cme-styles.min.css" rel="stylesheet" / -->
<div class="image-caption" style="width:694px;margin-top:0px;margin-bottom:px;margin-right:auto;margin-left:auto;">
<img alt="GET INSTANT ACCESS" src="https://via.placeholder.com/550x250" class="full-width lazyloaded" data-ll-status="loaded" border="0">
</div>
<form action="#" method="POST" sejds-popupally-pro-anti-spam-uengs="hts/t29ifsosf.o/p/ompoescc2e39092de8df6a" qweokgj-popupally-pro-anti-spam-mwhgser="tp:/s6.nuinotcmapfr/rcs/d9d04fde426bab8b" popupally-pro-popup="77" class="popupallypro-signup-form-sijfhw popupally-pro-inner-rwnkmg-77">
<div class="image-1-pro-rwnkmg"></div>
<div class="image-2-pro-rwnkmg"></div>
<div class="desc-pro-rwnkmg">
@chavesm
chavesm / 941392-mi-dynamic-link-label.php
Last active November 6, 2020 03:54
Set the data-vars-ga-label to the document.URL for dynamic custom event link label
// Put far down in footer as possible.
setTimeout(function() {
if (window.ga && ga.loaded) {
console.log('GA is loaded.');
} else {
console.log('GA is NOT loaded.');
// Maybe do more interesting things here.
}
}, 5000); // Give time for the page to load.
@chavesm
chavesm / post-id-custom-dimension-action-hook.php
Created October 13, 2020 08:06
WordPress action hook for sending a Post ID custom dimension value to Google Analytics.
<?php
add_action( 'wp_head', function () {
if (is_single ()) {
?>
<script>
// Post ID Custom Dimension Snippet
let dimension9Value = '<?php echo get_the_id() ?>';
//ga('set', 'dimension9', dimension9Value);
ga('send', 'event', 'dimension', 'Post ID', {
@chavesm
chavesm / mi-user-id-filter-functions.php
Last active January 28, 2021 12:43
MonsterInsights filter that supports displaying the login name (or full name) rather than an internal ID in Top logged-in report.
<?php
/**
* Custom Filter for the User ID Dimension
*
* Add this to your theme's functions.php file.
*/
function display_username_instead_of_user_id( $user_id ) {
$user = get_user_by( 'id', $user_id );
return $user->user_login;
@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 / 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 / ga-send-event-gtag.html
Last active March 5, 2021 08:36
Send an event to GA via MonsterInsights gtag version.
<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. -->