Skip to content

Instantly share code, notes, and snippets.

@octaedro
Last active July 15, 2022 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save octaedro/4559dc2b81cc01e2395795241bbba638 to your computer and use it in GitHub Desktop.
Save octaedro/4559dc2b81cc01e2395795241bbba638 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Add custom event to record
* Description: This plugin adds the code to test event recording validation (on the client side).
* Version: 0.1
*
*/
function add_custom_event() {
wc_enqueue_js(
"const recordEvent =
window.wc.tracks.recordEvent || window.wcTracks.recordEvent || function() {};
const props = confirm( 'Use broken props' ) ? { 'invalid-prop': 'foo' } : { valid_prop_name: 'bar' };
recordEvent( 'my_event', props );"
);
}
add_action( 'init', 'add_custom_event' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment