tl;dr: issues encountered when running Google Site Kit plugin on a local environment
Bypassing Site Kit’s development guards
sometimes production-like behaviour has to be tested
I was trying to fire Google Analytics events from a local test WordPress instance. Site Kit would not, though – turns out it has the concept of “guards”, which determine which features are available. The guard at work here, Tag_Production_Guard, checks if the WP environment is a production one, via wp_get_environment_type function.
The most obvious workaround would be to set WP_ENVIRONMENT_TYPE to 'production', but if it’s not possible (e.g. on Local), the code in the plugin has to be amended manually, since there seems to be no filter to change how this guard works edit: there is now!. This can be done with the googlesitekit_allowed_tag_environment_types filter, like so:
add_filter(
'googlesitekit_allowed_tag_environment_types',
function( $types ) {
$types[] = 'local';
return $types;
}
);
Leave a comment