Breadcrumbs

Magento

This is a guide to manually install Kelkoo Sales Tracking if you use Magento 1 or 2 (up to 2.3).

You need to edit part of your code to succeed with this implementation.

Before setting up your Kelkoo Sales Tracking Tag

Get your merchantId and associated Country Code

See How To get your merchantId and associated Country Code

Clean any old version of Kelkoo Sales Tracking

  • In your code, remove any Kelkoo Sales tracking tag (search for leadtag.js and _kkstrack)

  • On your website backend, uninstall any Kelkoo Sales Tracking plugin you might have installed

Magento 1

You need to install two elements:

  • the Leadtag, in charge of writing the cookie when the user first visits your website

  • the Conversion tag, in charge of retrieving data from the cookie and registering the sale

BOTH ARE MANDATORY FOR KELKOO SALES TRACKING TO WORK

Install the leadtag

Find and edit the right XML layout and add :

XML
<reference name="head">
  <block type="core/text" name="kelkoo.lead.tag">
      <action method="setText">
        <text>
          <![CDATA[<script type="text/javascript" src="https://s.kk-resources.com/leadtag.js"></script>]]>
        </text>
      </action>
  </block>
</reference>

Install the conversion tag

  • Paste this code at the end of the file. It gets the Order Value and the Order Id mandatory for Kelkoo Sales Tracking to work.

To add in web/app/design/frontend/custom/default/template/checkout/success.phtml, where custom is the name of your template.

PHP
<?php
  $orderObj = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
  $_totalData =$orderObj->getData();
?>

  • Right after the code added above, add the Conversion tag.

HTML
<script type="text/javascript">
  _kkstrack = {
    merchantInfo : [{ country:'COUNTRY_CODE', merchantId:'MERCHANTID_VALUE' }],
    orderValue: '<?=$_totalData['grand_total'] ?>',
    orderId: '<?=$this->getOrderId() ?>',
    basket:  []
  };
  (function() {
    var s = document.createElement('script');
    s.type = 'text/javascript';
    s.async = true;
    s.src = 'https://s.kk-resources.com/ks.js';
    var x = document.getElementsByTagName('script')[0];
    x.parentNode.insertBefore(s, x);
  })();
</script>

  • You need to edit some elements of the Conversion Tag. Those values can be hardcoded as they are the same for all the sales registered.

  • MERCHANTID_VALUE: This is the unique ID representing your shop within the Kelkoo Group system.

  • COUNTRY_CODE is the 2-letter country code (lower case) for the country on which your products are listed on Kelkoo Group. Check Full list of Kelkoo Group country codes

Magento 2

Install the leadtag

If you want to add Kelkoo Sales Tracking leadtag without creating a module, you can add the following code on your active theme.

To add in YourTheme/Magento_Theme/layout/default_head_blocks.xml

HTML
<script src="https://s.kk-resources.com/leadtag.js" src_type="url"/>

Install the Conversion tag

app/code/Kelkoo/Modulekelkoost/   
|- Block   
|    |- Success.php   
|- etc   
|    |- di.xml   
|    |- module.xml   
|- registration.php   
|- view   
|    |- frontend   
|    |     |-  layout   
|    |     |     |- checkout_onepage_success.xml   
|    |     |-  templates   
|    |     |     |- checkout   
|    |     |     |     |- success.phtml 

  • Modify app/code/Kelkoo/Modulekelkoost/view/frontend/templates/checkout/success.phtml to set the correct country and MerchantId

HTML
<?php /** @var $block \Kelkoo\Modulekelkoost\Block\Success */ ?>
<div>
    <?php if ($block->getOrder()->getId()):?>

<script type="text/javascript">
    var _kkstrack = {
      merchantInfo: [{ country:"country", merchantId:"MerchantId" }],
      orderValue: '<?=$block->getOrder()->getGrandTotal()?>',
      orderId: '<?=$block->getOrder()->getId() ?>'
    };
    (function() {
      var s = document.createElement('script');
      s.type = 'text/javascript';
      s.async = true;
      s.src = 'https://s.kk-resources.com/ks.js';
      var x = document.getElementsByTagName('script')[0];
      x.parentNode.insertBefore(s, x);
    })();
</script>
  <?php endif; ?>

</div>

  • Enable kelkoost module :

php bin/magento module:enable Kelkoo_Modulekelkoost 
php bin/magento setup:upgrade --keep-generated 

Test your integration

Please check Test Integration