Skip to content

Instantly share code, notes, and snippets.

@heyJordanParker
Created January 29, 2025 22:20
Show Gist options
  • Select an option

  • Save heyJordanParker/357e08d59d352a63656deaa4c0f6d26f to your computer and use it in GitHub Desktop.

Select an option

Save heyJordanParker/357e08d59d352a63656deaa4c0f6d26f to your computer and use it in GitHub Desktop.
Custom Bento Tracking
<?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