Created
January 29, 2025 22:20
-
-
Save heyJordanParker/357e08d59d352a63656deaa4c0f6d26f to your computer and use it in GitHub Desktop.
Custom Bento Tracking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action('wp_enqueue_scripts', 'custom_bento_tracking'); | |
| // bento tracking using my custom domain (so no ad blockers) | |
| function custom_bento_tracking() { | |
| $bento_options = get_option('bento_settings'); | |
| $bento_site_key = $bento_options['bento_site_key']; | |
| if (empty($bento_site_key)) { | |
| return; | |
| } | |
| wp_enqueue_script( | |
| 'bento-js', | |
| "https://kodama.creatorincome.co/nurikabe/{$bento_site_key}.js?woocommerce=1", | |
| [], | |
| false, | |
| true | |
| ); | |
| $params = getBentoWordpressSDKJSParams(); | |
| wp_localize_script('bento-js', 'bento_wordpress_sdk_params', $params); | |
| } | |
| function getBentoWordpressSDKJSParams() { | |
| $params = [ | |
| 'ajax_url' => admin_url('admin-ajax.php'), | |
| ]; | |
| $current_user = wp_get_current_user(); | |
| if (0 == $current_user->ID) { | |
| $params['user_logged_in'] = false; | |
| } else { | |
| $params['user_logged_in'] = true; | |
| $params['user_email'] = $current_user->user_email; | |
| } | |
| $params['woocommerce_enabled'] = class_exists('WooCommerce'); | |
| if ($params['woocommerce_enabled']) { | |
| $params['woocommerce_cart_count'] = WC()->cart | |
| ? WC()->cart->get_cart_contents_count() | |
| : 0; | |
| } | |
| return $params; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment