Add third party trackings in Magento

add third party tracking

If you need to add other tracking other than GA tracking on your website then you can do it two ways. One way is like the same way Magento has implemented GA tracking. This is the most efficient way. The other way is directly on individual pages (like all pages, product, basket, checkout, order confirmation etc).

But as we all know because of the time constraint and amount of trackings you need to implement on your site we all choose the second way i.e. directly on the individual pages.

Personally I would recommend you to do it Magento way but even if you want to use quick way then you can easily achieve this in a better way than just simply copy paste the tracking codes on individual pages.

You can create a simple module which will create required configurable variables of each tracking. This way you can enable or disable individual trackings and also implement the same tracking for multiple websites by changing configurable variable from admin portal.

Following is the step to step guide to add trackings -:

Step 1

Create a local module in app/local/Scommerce/Trackings

Step 2

Now create config.xml file in etc directory of Trackings module

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
        <Scommerce_Trackings>
            <version>0.0.1</version>
        </Scommerce_Trackings>
  </modules>
  <adminhtml>
    <acl>
        <resources>
            <admin>
             <children>
              <system>
                <children>
                  <config>
                    <children>
                      <scommerce_tracking translate="title">
                        <title>Scommerce Tracking</title>
                      </scommerce_tracking>
                     </children>
                    </config>
                  </children>
                 </system>
               </children>
             </admin>
          </resources>
      </acl>
  </adminhtml>
</config>

Step 3

Now create system.xml with your tracking configurations. In this case we are implementing ultimate feed tracking

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <tabs>
        <scommerce translate="label" module="cashback">
            <label>Scommerce Configuration</label>
            <sort_order>100</sort_order>
        </scommerce>
    </tabs>
    <sections>
        <scommerce_tracking translate="label">
            <label>Trackings</label>
            <tab>scommerce</tab>
            <sort_order>400</sort_order>
            <frontend_type>text</frontend_type>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
          <groups>
           <ultimate_feed translate="label">
            <label>Ultimate Feed</label>
            <sort_order>1</sort_order>
            <frontend_type>text</frontend_type>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <fields>
                <enabled translate="label">
                 <label>Enabled</label>
                 <sort_order>1</sort_order>
                 <frontend_type>select</frontend_type>
                 <source_model>adminhtml/system_config_source_yesno</source_model>
                 <show_in_default>1</show_in_default>
                 <show_in_website>1</show_in_website>
                 <show_in_store>1</show_in_store>
                </enabled>
                <company_id translate="label">
                  <label>Company Id</label>
                  <sort_order>2</sort_order>
                  <frontend_type>text</frontend_type>
                  <show_in_default>1</show_in_default>
                  <show_in_website>1</show_in_website>
                  <show_in_store>1</show_in_store>
                </company_id>
            </fields>
           </ultimate_feed>
          </groups>
     </scommerce_tracking>
    </sections>
</config>

Step 4

Now on individual pages, you can get the tracking variables using the following -:

The below tracking has been implemented on product page (view.phtml)

<?php 
$ultimate_feed_enabled = Mage::getStoreConfig("scommerce_tracking/ultimate_feed/enabled");

if ($ultimate_feed_enabled):
   $feed_company_id = Mage::getStoreConfig("scommerce_tracking/ultimate_feed/company_id");?>
   <script type="text/javascript"> 
       istCompanyId = "<?php echo $feed_company_id?>"; 
        istItem = "<?php echo $_product->getSKU()?>"; 
   </script> 
   <script type="text/javascript" 
     src="https://www.ist-track.com/ContainerItemJavaScript.ashx?id=<?php echo $feed_company_id?>">
   </script>
<?php endif;?>

The same way you can implement other trackings like Google Adword, affiliate window, shopfeed etc.

One thought on “Add third party trackings in Magento

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.