Add property to check if wcTracks is enabled

This commit is contained in:
Joshua Flowers 2020-05-13 16:53:57 +03:00
parent 07087c79a7
commit 3f9db6a558
1 changed files with 5 additions and 0 deletions

View File

@ -65,7 +65,12 @@ class WC_Site_Tracking {
<!-- WooCommerce Tracks -->
<script type="text/javascript">
window.wcTracks = window.wcTracks || {};
window.wcTracks.isEnabled = <?php echo self::is_tracking_enabled() ? 'true' : 'false'; ?>;
window.wcTracks.recordEvent = function( name, properties ) {
if ( ! window.wcTracks.isEnabled ) {
return;
}
var eventName = '<?php echo esc_attr( WC_Tracks::PREFIX ); ?>' + name;
var eventProperties = properties || {};
eventProperties.url = '<?php echo esc_html( home_url() ); ?>'