Skip to content

Instantly share code, notes, and snippets.

View chavesm's full-sized avatar

Mark Chaves chavesm

View GitHub Profile
<?php // Don't copy this line if adding this gist to a functions.php file.
function get_mepr_id() {
if ( !class_exists('MeprUtils') ) {
return 0;
}
$mepr_user = MeprUtils::get_currentuserinfo();
if ( $mepr_user === false ) {
@chavesm
chavesm / send-user-agent-custom-dimension.php
Created April 27, 2021 01:11
Send user agent as a custom dimension via MonsterInsights action hook
<?php // Remove this line when adding to child functions.php
/**
* This example sets custom dimension #14 to be the HTTP
* user agent.
*
* This is compatible with MonsterInsights gtag code. This filter supercedes
* the monsterinsights_frontend_tracking_options_analytics_before_pageview
* filter.
*
@chavesm
chavesm / mi-pop-posts-mobile-responsive-permanent-fix.css
Last active April 22, 2021 07:51
Short term fix to force Popular Post to fix on mobile portrait.
/** Permanent fix to force Popular Post to fix on mobile portrait. */
.monsterinsights-inline-popular-posts.monsterinsights-popular-posts-styled.monsterinsights-inline-popular-posts-november .monsterinsights-inline-popular-posts-title {
white-space: normal;
}
@chavesm
chavesm / send-social-click-to-ga-1209416.html
Last active April 18, 2021 09:23
Send a social media icon click event to GA using MonsterInsights gtag.js API.
<!-- Example HTML -->
<p>
<a
href="https://www.facebook.com"
onclick="sendSocialClick1209416('Facebook', 'https://streetphotography.blog');"
target="_blank"
rel="noopener">
Facebook
</a>
&nbsp;•&nbsp;
@chavesm
chavesm / mi-cookie-notice-with-ga-cookie-removal.js
Last active April 16, 2021 07:35
Disable or enable MonsterInsights (GA) tracking and force delete of _ga and _gid cookies if Cookie Notice consent is rejected.
@chavesm
chavesm / mi-enfold-cookie-consent-pub.js
Last active April 16, 2021 03:27
[Public] Disable MonsterInsights (Google Analytics) tracking and force delete of _ga and _gid cookies if the Enfold Cookie Consent is rejected.
@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;
}
@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 / 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.

[DRAFT]

Why is There No Data in My MonsterInsights Reports?

Is MonsterInsights installed and activated?

Do I have the latest MonsterInsights?

Is MonsterInsights connected to the correct property?