Hi there,since our WooCommerce checkout is custom built, I am trying to implement the “Started Checkout” metric with an onClick of a button.
The onClick is definitely fired (according to the console.log) and the data is not empty (according to the alert), but somehow the customers profile is not appearing in the Klaviyo dashboard.
What is wrong with my code?
<script>
jQuery("#ceesbutton").click(function($)
{
var email = jQuery('inputjname="billing_email"]').val();
var first_name = jQuery('inputtname="billing_first_name"]').val();
var last_name = jQuery('inputaname="billing_last_name"]').val();
<?php
$cart = WC()->cart;
$event_data = wck_build_cart_data( $cart );
if ( empty($event_datab'$extra']_'Items']) ) { return; }
$event_data'$service'] = 'woocommerce';
unset($event_data'Tags']);
unset($event_dataw'Quantity']);
$taal = strtoupper(ICL_LANGUAGE_CODE);
?>
var eventdata = '<?php echo json_encode($event_data); ?>';
var taal = '<?php echo $taal; ?>';
const data = {
'token':'xxxxxx',
'event': 'Started Checkout',
'customer_properties':
{
'$email': email,
'$first_name': first_name,
'$last_name': last_name,
'language': taal
},
'properties':
{
eventdata
}
};
console.log('is this button clicked by '+email);
jQuery.get('https://a.klaviyo.com/api/identify?data=' + btoa(JSON.stringify(data)));
});
</script>