Skip to main content

Marketing Integrations

ScentLok integrates with multiple marketing platforms for email marketing, reviews, analytics, and customer engagement.

Overview

PlatformPurposeVersion/ID
KlaviyoEmail marketingCompany: VE7rVK
BazaarVoiceReviews & ratingsIntegrator v1.1.4
Google Tag ManagerTag managementGTM4WP v1.20.3
SLoyaltyLoyalty programAPI Key: e6838c7d

Klaviyo Integration

Overview

Company ID: VE7rVK
Purpose: Email marketing, automation, and customer data platform

Configuration

// wp-config.php
define( 'KLAVIYO_API_KEY', 'your-private-api-key' );
define( 'KLAVIYO_COMPANY_ID', 'VE7rVK' );
define( 'KLAVIYO_PUBLIC_API_KEY', 'your-public-api-key' );

Product Tracking

Track product views for personalized recommendations:

// Track product view in Klaviyo
add_action( 'wp_footer', function() {
if ( is_singular( 'bigcommerce_product' ) ) {
global $post;

$product_data = [
'ProductName' => get_the_title(),
'ProductID' => get_post_meta( $post->ID, 'bc_id', true ),
'SKU' => get_post_meta( $post->ID, 'bc_sku', true ),
'ImageURL' => get_the_post_thumbnail_url( $post->ID, 'large' ),
'URL' => get_permalink(),
'Price' => get_post_meta( $post->ID, 'bc_price', true ),
'Categories' => wp_list_pluck( get_the_terms( $post->ID, 'bc_category' ), 'name' ),
];
?>
<script>
var _learnq = _learnq || [];
_learnq.push(['track', 'Viewed Product', <?php echo json_encode( $product_data ); ?>]);
</script>
<?php
}
});

Add to Cart Tracking

// Track add to cart events
document.addEventListener('cartItemAdded', function(e) {
const product = e.detail;

var _learnq = _learnq || [];
_learnq.push(['track', 'Added to Cart', {
'$value': product.price,
'ProductName': product.name,
'ProductID': product.id,
'SKU': product.sku,
'Categories': product.categories,
'ImageURL': product.image,
'URL': product.url,
'Price': product.price,
'Quantity': product.quantity
}]);
});

Started Checkout Tracking

// Track checkout started
add_action( 'template_redirect', function() {
if ( is_page( 'checkout' ) ) {
$cart = get_cart_data();
?>
<script>
var _learnq = _learnq || [];
_learnq.push(['track', 'Started Checkout', {
'$value': <?php echo esc_js( $cart['total'] ); ?>,
'ItemNames': <?php echo json_encode( $cart['item_names'] ); ?>,
'CheckoutURL': '<?php echo esc_js( $cart['checkout_url'] ); ?>',
'Items': <?php echo json_encode( $cart['items'] ); ?>
}]);
</script>
<?php
}
});

Order Completed Tracking

// Track order completion
add_action( 'bigcommerce/order/created', function( $order_id, $order_data ) {
$customer_email = $order_data['billing_address']['email'];

$klaviyo_data = [
'token' => KLAVIYO_API_KEY,
'event' => 'Placed Order',
'customer_properties' => [
'$email' => $customer_email,
'$first_name' => $order_data['billing_address']['first_name'],
'$last_name' => $order_data['billing_address']['last_name'],
],
'properties' => [
'$event_id' => $order_id,
'$value' => $order_data['total_inc_tax'],
'OrderId' => $order_id,
'Categories' => array_unique( wp_list_pluck( $order_data['products'], 'category' ) ),
'ItemNames' => wp_list_pluck( $order_data['products'], 'name' ),
'Items' => array_map( function( $item ) {
return [
'ProductID' => $item['product_id'],
'SKU' => $item['sku'],
'ProductName' => $item['name'],
'Quantity' => $item['quantity'],
'ItemPrice' => $item['price_inc_tax'],
'RowTotal' => $item['total_inc_tax'],
'ImageURL' => $item['image_url'],
];
}, $order_data['products'] ),
],
];

wp_remote_post( 'https://a.klaviyo.com/api/track', [
'body' => json_encode( $klaviyo_data ),
'headers' => [ 'Content-Type' => 'application/json' ],
]);
}, 10, 2 );

Newsletter Signup Forms

// Klaviyo subscribe form shortcode
add_shortcode( 'klaviyo_signup', function( $atts ) {
$atts = shortcode_atts([
'list_id' => '',
'title' => 'Subscribe to Our Newsletter',
], $atts );

ob_start();
?>
<div class="klaviyo-signup-form">
<h3><?php echo esc_html( $atts['title'] ); ?></h3>
<form class="klaviyo-form" data-list-id="<?php echo esc_attr( $atts['list_id'] ); ?>">
<input
type="email"
name="email"
placeholder="Enter your email"
required
class="w-full px-4 py-2 border rounded-md mb-2"
/>
<button type="submit" class="btn-primary w-full py-2 rounded-md">
Subscribe
</button>
</form>
</div>

<script>
document.querySelector('.klaviyo-form').addEventListener('submit', async function(e) {
e.preventDefault();

const email = this.email.value;
const listId = this.dataset.listId;

const response = await fetch('/wp-json/klaviyo/v1/subscribe', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, list_id: listId })
});

if (response.ok) {
alert('Thank you for subscribing!');
this.reset();
}
});
</script>
<?php
return ob_get_clean();
});

// Handle subscribe endpoint
add_action( 'rest_api_init', function() {
register_rest_route( 'klaviyo/v1', '/subscribe', [
'methods' => 'POST',
'callback' => 'handle_klaviyo_subscribe',
'permission_callback' => '__return_true',
]);
});

function handle_klaviyo_subscribe( $request ) {
$email = sanitize_email( $request->get_param( 'email' ) );
$list_id = sanitize_text_field( $request->get_param( 'list_id' ) );

$response = wp_remote_post( "https://a.klaviyo.com/api/v2/list/{$list_id}/subscribe", [
'headers' => [
'Content-Type' => 'application/json',
],
'body' => json_encode([
'api_key' => KLAVIYO_API_KEY,
'profiles' => [
[
'email' => $email,
'$consent' => 'email',
],
],
]),
]);

if ( is_wp_error( $response ) ) {
return new WP_Error( 'klaviyo_error', $response->get_error_message() );
}

return new WP_REST_Response([ 'success' => true ], 200 );
}

Abandoned Cart Recovery

// Track abandoned carts
add_action( 'wp_ajax_update_cart', 'track_cart_update' );
add_action( 'wp_ajax_nopriv_update_cart', 'track_cart_update' );

function track_cart_update() {
if ( ! is_user_logged_in() ) {
return;
}

$user = wp_get_current_user();
$cart = get_cart_data();

// Send to Klaviyo
$klaviyo_data = [
'token' => KLAVIYO_API_KEY,
'event' => 'Cart Updated',
'customer_properties' => [
'$email' => $user->user_email,
],
'properties' => [
'$value' => $cart['total'],
'ItemNames' => $cart['item_names'],
'CartURL' => home_url( '/cart' ),
'Items' => $cart['items'],
],
];

wp_remote_post( 'https://a.klaviyo.com/api/track', [
'body' => json_encode( $klaviyo_data ),
'headers' => [ 'Content-Type' => 'application/json' ],
]);
}

BazaarVoice Integration

Overview

Reviews and ratings platform with automated feed generation.

Display Reviews on Product Pages

// Add BazaarVoice reviews container
add_action( 'bigcommerce/product/after_content', function( $post_id ) {
$bc_id = get_post_meta( $post_id, 'bc_id', true );
?>
<div id="BVRRContainer" data-product-id="<?php echo esc_attr( $bc_id ); ?>"></div>

<script>
$BV.ui('rr', 'show_reviews', {
productId: '<?php echo esc_js( $bc_id ); ?>',
doShowContent: true
});
</script>
<?php
});

Inline Ratings

// Display star rating on product cards
function display_bv_inline_rating( $bc_id ) {
?>
<div class="bv-inline-rating" data-bv-show="inline_rating" data-bv-product-id="<?php echo esc_attr( $bc_id ); ?>"></div>

<script>
$BV.ui('rr', 'inline_ratings', {
productIds: ['<?php echo esc_js( $bc_id ); ?>']
});
</script>
<?php
}

Schema.org Markup

// Add structured data for reviews
add_action( 'wp_head', function() {
if ( is_singular( 'bigcommerce_product' ) ) {
global $post;

$bc_id = get_post_meta( $post->ID, 'bc_id', true );
$rating_data = get_bv_rating_data( $bc_id );

if ( $rating_data ) :
?>
<script type="application/ld+json">
{
"@context": "https://schema.org/",
"@type": "Product",
"name": "<?php echo esc_js( get_the_title() ); ?>",
"image": "<?php echo esc_js( get_the_post_thumbnail_url( $post->ID, 'large' ) ); ?>",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "<?php echo esc_js( $rating_data['rating'] ); ?>",
"reviewCount": "<?php echo esc_js( $rating_data['count'] ); ?>"
}
}
</script>
<?php
endif;
}
});

Google Tag Manager

Overview

Plugin: Google Tag Manager for WordPress v1.20.3
Purpose: Tag management and analytics tracking

Configuration

// GTM Container ID
define( 'GTM_CONTAINER_ID', 'GTM-XXXXXXX' );

E-commerce Events

GTM4WP automatically tracks e-commerce events:

  • Product impressions
  • Product clicks
  • Product details
  • Add to cart
  • Remove from cart
  • Checkout steps
  • Purchases

Custom Data Layer Variables

// Add custom data layer variables
add_filter( 'gtm4wp_add_datalayer_product', function( $data, $post_id ) {
$data['productBrand'] = get_product_brand( $post_id );
$data['productCondition'] = 'new';
$data['availability'] = get_post_meta( $post_id, 'bc_inventory_level', true ) > 0 ? 'in stock' : 'out of stock';

return $data;
}, 10, 2 );

// Add user data to data layer
add_filter( 'gtm4wp_datalayer_json_encode', function( $datalayer ) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
$datalayer['userId'] = $user->ID;
$datalayer['userEmail'] = hash( 'sha256', $user->user_email );
$datalayer['customerType'] = get_user_meta( $user->ID, 'customer_type', true ) ?: 'regular';
}

return $datalayer;
});

Enhanced E-commerce Tracking

// Push enhanced e-commerce events
dataLayer.push({
'event': 'productView',
'ecommerce': {
'detail': {
'products': [{
'name': 'Product Name',
'id': '12345',
'price': '99.99',
'brand': 'ScentLok',
'category': 'Hunting Apparel',
'variant': 'Large/Camo'
}]
}
}
});

Conversion Tracking

// Track order as conversion
add_action( 'bigcommerce/order/created', function( $order_id, $order_data ) {
?>
<script>
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'purchase': {
'actionField': {
'id': '<?php echo esc_js( $order_id ); ?>',
'affiliation': 'ScentLok',
'revenue': '<?php echo esc_js( $order_data['total_inc_tax'] ); ?>',
'tax': '<?php echo esc_js( $order_data['total_tax'] ); ?>',
'shipping': '<?php echo esc_js( $order_data['shipping_cost_inc_tax'] ); ?>',
'coupon': '<?php echo esc_js( $order_data['coupon_discount'] ); ?>'
},
'products': <?php echo json_encode( array_map( function( $item ) {
return [
'name' => $item['name'],
'id' => $item['product_id'],
'price' => $item['price_inc_tax'],
'brand' => $item['brand'],
'category' => $item['category'],
'variant' => $item['variant'],
'quantity' => $item['quantity'],
];
}, $order_data['products'] ) ); ?>
}
}
});
</script>
<?php
}, 10, 2 );

Facebook Pixel

Configuration

// Add Facebook Pixel
add_action( 'wp_head', function() {
?>
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<?php
});

Track Add to Cart

// Facebook Pixel - Add to Cart
document.addEventListener('cartItemAdded', function(e) {
const product = e.detail;

fbq('track', 'AddToCart', {
content_name: product.name,
content_ids: [product.id],
content_type: 'product',
value: product.price,
currency: 'USD'
});
});

Track Purchase

// Facebook Pixel - Purchase
add_action( 'bigcommerce/order/created', function( $order_id, $order_data ) {
?>
<script>
fbq('track', 'Purchase', {
content_ids: <?php echo json_encode( wp_list_pluck( $order_data['products'], 'product_id' ) ); ?>,
content_type: 'product',
value: <?php echo esc_js( $order_data['total_inc_tax'] ); ?>,
currency: 'USD'
});
</script>
<?php
}, 10, 2 );

Marketing Automation

Customer Segmentation

// Tag customers based on behavior
add_action( 'bigcommerce/order/created', function( $order_id, $order_data ) {
$customer_email = $order_data['billing_address']['email'];
$order_total = $order_data['total_inc_tax'];

// High-value customer
if ( $order_total > 500 ) {
tag_customer_in_klaviyo( $customer_email, 'High Value Customer' );
}

// Category-based segmentation
$categories = wp_list_pluck( $order_data['products'], 'category' );
if ( in_array( 'Carbon Alloy', $categories ) ) {
tag_customer_in_klaviyo( $customer_email, 'Carbon Alloy Buyer' );
}
}, 10, 2 );

function tag_customer_in_klaviyo( $email, $tag ) {
wp_remote_post( 'https://a.klaviyo.com/api/v1/person', [
'headers' => [ 'Content-Type' => 'application/json' ],
'body' => json_encode([
'token' => KLAVIYO_API_KEY,
'properties' => [
'$email' => $email,
'tags' => [ $tag ],
],
]),
]);
}

Personalized Product Recommendations

// Display personalized recommendations
add_action( 'bigcommerce/product/after_content', function( $post_id ) {
if ( is_user_logged_in() ) {
$recommendations = get_klaviyo_recommendations( wp_get_current_user()->user_email );

if ( $recommendations ) :
?>
<section class="personalized-recommendations">
<h3>Recommended for You</h3>
<div class="product-grid">
<?php foreach ( $recommendations as $product_id ) : ?>
<?php display_product_card( $product_id ); ?>
<?php endforeach; ?>
</div>
</section>
<?php
endif;
}
});

Performance Monitoring

Track Page Load Times

// Send page load times to Google Analytics
window.addEventListener('load', function() {
const timing = performance.timing;
const loadTime = timing.loadEventEnd - timing.navigationStart;

gtag('event', 'timing_complete', {
name: 'load',
value: loadTime,
event_category: 'Page Load'
});
});

Troubleshooting

Verify Klaviyo Tracking

// Check Klaviyo queue
console.log(_learnq);

Verify GTM DataLayer

// Check data layer
console.log(dataLayer);

Test BazaarVoice

// Check BV object
console.log($BV);