2

Have to add different Affiliate tracking pixels on Homepage, Product Pages & Cart. Its a multi store Magento with different country domains - .AU, .DE, .UK

How can I add it to multiple stores ? What's the best approach for this?

A sample script for DE - Homepage Only -

<script type="text/javascript">
var belboonTag = {};
</script>
<script type="text/javascript" src="http://containertags.belboon.de/belboonTag.js.php?pId=xxxxx&page=start&type=dynamic"></script>
2

Add this to your one of your layout xml files.

<cms_index_index><!-- handle for homepage -->
    <reference name="content">
         <block type="core/template" template="affiliate/homepage.phtml" name="affiliate" as="affiliate" after="-" />
    </reference>
</cms_index_index>

<catalog_product_view><!-- handle for product view page -->
    <reference name="content">
         <block type="core/template" template="affiliate/product.phtml" name="affiliate" as="affiliate" after="-" />
    </reference>
</catalog_product_view>

<checkout_cart_index><!-- handle for cart page -->
    <reference name="content">
         <block type="core/template" template="affiliate/cart.phtml" name="affiliate" as="affiliate" after="-" />
    </reference>
</checkout_cart_index>

then create the files affiliate/homepage.phtml, affiliate/product.phtml, affiliate/cart.phtml inside the folder app/design/frontend/base/default/temaplte/ and add your corresponding codes in each one of the files.

If the codes are the same (but I doubt it) you can use the same template.

If you need the product id or sku inside the tracking code for the product page you can get it like this:

<?php productId = Mage::registry('current_product')->getId()?>
<?php productSku = Mage::registry('current_product')->getSku()?>
  • Thanks for help Marius. Which Layout file should I add the above code to? I would also need it for Category page, Order Confirmation page. And how can I implement all the above for different store domains? All of them use a single theme. UK, US, AU, DE – sunny155 Jul 16 '14 at 8:17
  • 1
    for category the layout handle is catalog_category_view and for order confirmation page is checkout_onepage_success. Do the same as above for both of them. If you need different codes on different websites I suggest storing the tracking code in System->configuration and read it from there. You can create a setting for each page and the scope of the config can be 'website' or 'store view'. – Marius Jul 16 '14 at 8:19
  • Thanks, where in System->configuration can I store the code? and how to read them in the above files? – sunny155 Jul 16 '14 at 9:16
  • Here is a nice article about this: inchoo.net/ecommerce/magento/… – Marius Jul 16 '14 at 9:18
  • Ok, I am creating a custom extension. In which layout xml file should I add the above codes? – sunny155 Jul 16 '14 at 10:40
1

I guess you could just create number static blocks containing you pixel that are assigned to appropriate view scopes and let Magento do the rest. You could of course play around with themes, but this is by far the simplest way.

Of course you need to add those static block to different pages in layout files (local.xml would do), just adding them to default is not good enough. Home page is cms_index_index, catalog_product_view is for product view and checkout_cart_index is for cart.

  • it works with static blocks only if you don't need dynamic data in the tracking code. But in the example there is this pId=xxxxx. I assume that's the product id and is different from page to page. In this case it won't work with static blocks. – Marius Jul 16 '14 at 7:16
  • Well we don't know .. it could as well be account id. Hmm ... this actually gives me an idea for the extension: {{product_id}} dynamic tag for product pages :D – Pronto Jul 16 '14 at 7:24
  • Like I said..."I assume". If there is not data depending on the context, this is a nice way to go. – Marius Jul 16 '14 at 7:28
  • Yes, if it is a product id, then my method is no good. Ah, and get current product id only works for product pages. – Pronto Jul 16 '14 at 7:33
  • It will work only for homepage as it don't need any dynamic data. But for Category Page I need to pass Category ID, for Product Page - Category ID, Price and Product ID. So static blocks wont work for this. – sunny155 Jul 16 '14 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.