Adding an E-commerce Tracking Code

Andrew Chornyy - 001
Andrew Chornyy

CEO Plerdy — expert in SEO&CRO with over 14 years of experience.

Setting up your online store’s sales performance tracking in Plerdy requires basic HTML and JavaScript editing skills. If you’re not comfortable with this, consider seeking help from a specialist.

e-commerce tracking code

With Plerdy’s online store sales performance tracking, you can monitor key data such as:

  1. Number of transactions during a selected period.
  2. Number of unique users who made purchases.
  3. Total revenue of the online store.
  4. Conversion rate of the online store.
  5. Average order value.
  6. Quantity of products sold.


e-commerce tracking

These metrics are categorized by traffic type and device, allowing you to analyze which sources are most profitable. Furthermore, Plerdy helps identify which elements of your store contribute to successful orders and their generated profit.

Steps for Implementation

To initiate Plerdy’s sales performance data collection, follow these steps:

  1. Copy the following script template:
  2. <script type="text/javascript" defer>
    var plerdysendData = {'type':'commerce', 'data':
    {'order_id':'ORDER_ID', 'money':TOTAL_AMOUNT, 'quantity':QUANTITY}}
    </script>

    Note: TOTAL_AMOUNT should be a numeric value without currency, for example, 12.42.

  3. Replace ‘ORDER_ID’, TOTAL_AMOUNT, and QUANTITY with dynamic variables reflecting your store’s transaction data.
  4. Install the edited script on your order success page.
  5. Create a test order and check the Sales Performance tab in Plerdy. Verify that the data matches your order details.
  6. If all data is correct, your sales performance tracking is now active.

Examples for Implementing Tracking Code

WordPress Woocommerce

You can add the tracking code by automatically installing the WP plugin.

Shopify

You can add the tracking code by automatically installing the Shopify app.

Magento

<script type="text/javascript" defer>
    var plerdysendData = {'type':'commerce', 'data':
{'order_id':<?php echo $block->getRealOrderId(); ?>, 'money': <?php echo $order_details->total_paid; ?>, 'quantity':<?php echo $quantity_variable; ?>}
</script>

Note: Ensure that the $quantity_variable correctly reflects the number of products in the order.

Opencart

\catalog\controller\checkout\success.php
Before
$this->cart->clear();

$data['ids'] = $this->session->data['order_id'];
$data['products'] = $this->cart->getProducts();
$ids = $data['products'];
$money = 0;
$quantity = 0;
foreach ($ids as $idse){
    $money = $money + $idse['total'];
    $quantity = $quantity + $idse['quantity'];
}
$data['money'] = $money;
$data['quantity'] = $quantity;

\catalog\view\theme\...\template\common\success.twig

<script type="text/javascript" defer>
    var plerdysendData = {'type':'commerce', 'data':
{'order_id':{{ ids }}, 'money':{{ money }}, 'quantity':{{ quantity }} }}}
</script>

CodeIgniter

{if strstr($CI->uri->uri_string(),'/order/view/')}
<script type="text/javascript" defer>
{literal}
var plerdysendData = {'type':'commerce', 'data': {'order_id':{/literal}

{echo $model->getId()}{literal},'money':{/literal}
{echo $model->getTotalPrice()}{literal}, 'quantity':{/literal}
{echo $model->getQuantity()} }}}
{literal} </script> {/if}

Note: Ensure that the getQuantity() function correctly returns the number of products in the order.

Wix

<?php
$order = json_decode($order);
$orderid = $order['order']['id'];
$ordertotal = $order['totals']['total'];
$orderquantity = $order['totals']['quantity'];
?>
<script type="text/javascript" defer>
    var plerdysendData = {'type':'commerce', 'data':
{'order_id':<?php echo $orderid; ?>, 'money': <?php echo $ordertotal; ?>,
'quantity':<?php echo $orderquantity; ?>}}
</script>

Google Tag Manager

You can also add an e-commerce tracking code via GTM.

Testing

Perform the following steps on your page in Chrome Incognito:

  1. Click on various elements on a single page.
  2. Make a test purchase.
  3. In the menu panel, select “Today” and activate the report.

You will see which elements have been assigned the purchase amount.

e-commerce tracking code

Was this helpful?