Web Tracking for Opencart Browse Abandonment

Step 1 - Adding Remarkety's tracking code to the footer of all pages

  1. 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;
  2. Save the file and close it.
  3. 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 --->
  4. 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
    1.png
  5. Save the file and close it.

Step 2 - Adding the product view tracking code

  1. 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;
  2. Save the file and close it.
  3. 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 ---->
  4. 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. 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.