Skip to content

Instantly share code, notes, and snippets.

View chavesm's full-sized avatar

Mark Chaves chavesm

View GitHub Profile
@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
@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 / mi-set-data-vars-ga-label-for-images.php
Last active November 17, 2021 15:01
Custom Event Link Label For Image Links
<?php
/**
* Add to Child Theme's functions.php.
*/
add_action( 'wp_footer', function () {
if (is_page ('2')) {
?>
<script>// Custom Label Snippet
let dl948914 = document.querySelector("a");
@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 / 949478-form-conversion-event.js
Last active November 17, 2021 14:58
Form Conversion Event (949478)
if (document.URL === "https://myverycool.site/form-page/") {
const subBtn949478 = document.querySelector(
"form#avia_contact_6935_contact-us-about input.button"
);
if (subBtn949478) {
subBtn949478.addEventListener(
"click",
function (evt) {
__gaTracker(
"send",
@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 / 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/[email protected]/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 / 974747-dg-divi-carousel-frontend-bundle.js
Last active January 15, 2024 15:13
A mockup for sending an impression to GA for every slide displayed by Swiper JS from the DG Divi Slider Carousel Plugin
@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', {
// 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.