Step 1 - Adding Remarkety's tracking code to the footer of all pages
- On your OpenCart root folder, edit the file: /catalog/controller/common/footer.php
And add the following line to the index() function before the "return" statement:
$data['customer_email'] = $this->customer->isLogged() ? $this->customer->getEmail() : null;
- Save the file and close it.
- Edit the file /catalog/view/theme/default/template/common/footer.tpl
Add the following code before the </body> tag:
<!--- Remarkety Customer ---->
<script>
var _rmData = _rmData || [];
_rmData.push(['setStoreKey', 'STORE_ID']);
<?php if(!empty($customer_email)): ?>
_rmData.push(["setCustomer", "<?php echo $customer_email; ?>"]);
<?php endif; ?>
</script>
<script>(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = 'https://d3ryumxhbd2uw7.cloudfront.net/webtracking/track.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));</script>
<!--- End of Remarkety Customer ---> - Make sure to replace STORE_ID with the store id from the API Key page on Remarkety -
https://app.remarkety.com/account/storesettings#tab_api_keys - Save the file and close it.
Step 2 - Adding the product view tracking code
- Edit the file /catalog/controller/product/product.php
In function index(), after the following line (around line 161):
$product_info = $this->model_catalog_product->getProduct($product_id);
Add this code:
$categories = $this->model_catalog_product->getCategories($product_id);
$categoriesIds = array();
$categoriesNames = array();
foreach($categories as $cat){
$category = $this->model_catalog_category->getCategory($cat['category_id']);
$categoriesIds[] = $cat['category_id'];
$categoriesNames[] = $category['name'];
}
$data['categoriesIds'] = $categoriesIds;
$data['categoriesNames'] = $categoriesNames; - Save the file and close it.
- Edit the file /catalog/view/theme/default/template/product/product.tpl
Just before the last line ( <?php echo $footer; ?> ) add the following code:
<!--- Remarkety Product view ---->
<script>
var _rmData = _rmData || [];
_rmData.push(['productView', {
productId: <?php echo $product_id; ?>,
productCategories: <?php echo json_encode($categoriesNames); ?>,
productCategoriesIds: <?php echo json_encode($categoriesIds); ?>,
price: <?php echo json_encode($price); ?>,
brand: <?php echo json_encode($manufacturer); ?>
}]);
</script>
<!--- End of Remarkety Product view ----> - Save the file and close it.
You're all set!
You can monitor your recent website tracking events on Remarkety here: https://app.remarkety.com/account/storesettings#tab_webtracking
If you have any additional questions, please feel free to contact support@remarkety.com.
Comments
0 comments