SlideShare a Scribd company logo
1 of 13
How to Create Module to Track Affiliate Conversions?
Do you or the affiliate marketer know which conversions have been made by you, and which
conversions are made through the affiliate referrals? Do you inform your affiliate whenever a
conversion is made through their referral? Instead of keeping track manually, Magento allows you
to create a module that will track affiliate referrals and notify whenever the referral is converted.
The Pre-requisites
By now you must be aware with the basics of Magento and coding. You must have familiarized
yourself with creating Magento modules.
Whenever you are making certain website specific settings, you would add them as configurable
options in the admin panel. That’s why the module you are coding for affiliate conversions will
become a community module and will be stored in the following path app/code/community. When
you create a community module or code, you are actually allowing future use of the module, as it is,
without any modifications.
To create a module to track affiliate conversions, you will need to create empty file structures
containing empty files
Here’s a code that will help you create this structure
app
- code
- community
- Affiliate
- Block
- Conversion.php
- Model
- Observer.php
- etc
- config.xml
- design
- frontend
- base
- default
- layout
- Example_affiliate.xml
- template
- Example_affiliate
- conversion.phtml
- etc
- modules
- Example_Affiliate.xml
To add content for the example module, here is the code
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<modules>
<Example_Affiliate>
<active>true</active>
<codePool>community</codePool>
</Example_Affiliate>
</modules>
</config>
Steps to Track the Affiliate Referral
When you set out to track affiliates, the first thing you track is the content that referred your
website. Was it a website, a newsletter, or similar kind of content that included your website
details? You will also need to know the affiliate ID to reward the affiliate once the conversion has
been made
Example.com/&quest;utm_source=some_affiliate_id
The Event Observer
$_GET parameter is used to fetch a particular URL and use it for affiliate marketing. It is necessary
for you, as a store to include this parameter throughout your website, so that affiliates can link the
page containing the product/service of interest to their readers or users.
You should not bring any changes to the core. That’s why it is necessary to use event_observer that
will connect with the pages and fetch the required data
The single event that will be dispatched across the different parts of the website would be
controller_front_init_before
Let’s create a config.xml along with an observer for this particular event
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<modules>
<Example_Affiliate>
<version>0.0.1</version>
</Example_Affiliate>
</modules>
<global>
<models>
<Example_affiliate>
<class>Example_Affiliate_Model</class>
</Example_affiliate>
</models>
<events>
<controller_front_init_before>
<observers>
<Example_affiliate>
<class>Example_affiliate/observer</class>
<method>captureReferral</method>
<type>singleton</type>
</Example_affiliate >
</observers>
</controller_front_init_before>
</events>
</global>
</config>
To capture the referral the following function will be called
Example_Affiliate_Model_Observer::captureReferral()
It is important to add content to observer.php that you have just created so that the referral can
fetch some data
<&quest;php
class Example_Affiliate_Model_Observer
{
public function captureReferral(Varien_Event_Observer $observer)
{
// here we add the logic to capture the referring affiliate ID
}
}
Capturing and Saving Affiliate ID
To capture the affiliate ID, the event observer that you just created controller_front_init_before will
be sent out from the Magento core defined by Mage_Core_Controller_Varien_Front::init() along with
a reference specified for the same class as defined in the event dispatched from
app/code/core/Mage/Core/Controller/Varien/Front.php. The code snippet used to dispatch the
event is
Mage::dispatchEvent(
'controller_front_init_before',
array('front' => $this)
);
If you want to gain access to the core file defined by Mage_Core_Controller_Varien_Front you will
need to paste the code given below to your event_observer module
<&quest;php
class Example_Affiliate_Model_Observer
{
public function captureReferral(Varien_Event_Observer $observer)
{
$frontController = $observer->getEvent()->getFront();
}
}
This controller checks and analyzes the different URLs that are passed through it. Through this, you
are able to access the object. Now, you need to check for $_GET parameter within this object. The
following code will help you perform the necessary action
<&quest;php
class Example_Affiliate_Model_Observer
{
public function captureReferral(Varien_Event_Observer $observer)
{
$frontController = $observer->getEvent()->getFront();
$utmSource = $frontController->getRequest()
->getParam('utm_source', false);
if ($utmSource) {
// here we will save the referrer affiliate ID
}
}
}
Here the getRequest() is used to regain the contents of Mage_Core_Controller_Request_Http
instance present within the controller. This instance will possess all the requisite details related to
the URL including the $_Post and $_Get parameters. Using the getParam() method, you can easily
retrieve the required details. $utmsource will contain the affiliate ID referring the link
Now, you know the affiliate ID. You will need to save the details so that you can reward the affiliate
in case the user who has clicked the link gets converted.
As you are aware, Magento has a core functionality of dealing with Cookies. You can easily use
$_COOKIE to save the $utmsource for the affiliate
<&quest;php
class Example_Affiliate_Model_Observer
{
const COOKIE_KEY_SOURCE = 'Example_affiliate_source';
public function captureReferral(Varien_Event_Observer $observer)
{
$frontController = $observer->getEvent()->getFront();
$utmSource = $frontController->getRequest()
->getParam('utm_source', false);
if ($utmSource) {
Mage::getModel('core/cookie')->set(
self::COOKIE_KEY_SOURCE,
$utmSource,
$this->_getCookieLifetime()
);
}
}
protected function _getCookieLifetime()
{
$days = 30;
// convert to seconds
return (int)86400 * $days;
}
}
Constants are truly useful when you need to use the same value across locations. In this code
constant COOKIE_KEY_SOURCE has been defined. With a constant, you don’t need to keep changing
the code with change in values. The code _getcookielifetime() has been defined to retrieve the
cookie for a lifetime. You can always define your lifetime. In this case, the number of days has been
set to 30 days.
Notifying the Affiliate on Conversion
The above processes have allowed us to include the affiliate ID in the cookie. Let’s say the customer
who has been referenced to your website has successfully checked out fromyour website. Now, you
need to notify the affiliate about the conversion, and reward them.
You can create event_observer and notify using the server side API. In this case, Magento layout and
introduce the necessary HTML code at the bottom of the page declaring order success
In order to perform this, you will need to update config.xml to introduce the different blocks and
layout created for this purpose
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<modules>
<Example_Affiliate>
<version>0.0.1</version>
</Example_Affiliate>
</modules>
<global>
<blocks>
<Example_affiliate>
<class>Example_Affiliate_Block</class>
</Example_affiliate>
</blocks>
<models>
<Example_affiliate>
<class>Example_Affiliate_Model</class>
</Example_affiliate>
</models>
<events>
<controller_front_init_before>
<observers>
<Example_affiliate>
<class>Example_affiliate/observer</class>
<method>captureReferral</method>
<type>singleton</type>
</Example_affiliate >
</observers>
</controller_front_init_before>
</events>
</global>
<frontend>
<layout>
<updates>
<Example_affiliate
module="Example_Affiliate">
<file>Example_affiliate.xml</file>
</Example_affiliate>
</updates>
</layout>
</frontend>
</config>
Adding New Layout with Template Files and Custom Blocks
You will need to modify the layout handle onepage_checkout_success. For this you will need to
update the layout file Example_affiliate.xml
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<layout>
<checkout_onepage_success>
<reference name="before_body_end">
<block type="Example_affiliate/conversion"
name="Example_affiliate_conversion"
template="Example_affiliate/conversion.phtml" />
</reference>
</checkout_onepage_success>
</layout>
Using the below code you can define a new template file. Contents for conversion.phtml will be
affiliate specific. For the sake of simplicity, the code being considered here is generic
<img
src="http://media.Example.com/themes/Examplev4/images/logo.png
&quest;merchant_id=<&quest;php echo $this->getMerchantId() &quest;>
&affiliate_id=<&quest;php echo $this->getAffiliateId() &quest;>"
width="1"
height="1"
/>
Now, you need to create a custom block to enter the data
<&quest;php
class Example_Affiliate_Block_Conversion
extends Mage_Core_Block_Template
{
public function getMerchantId()
{
return '12345';
}
public function getAffiliateId()
{
return Mage::getModel('core/cookie')->get(
Example_Affiliate_Model_Observer::COOKIE_KEY_SOURCE
);
}
}
Next go to System>Configuration and start configuring the different elements that would be needed
for each Magento instance
Configuring a New System Configuration Tab
For the purpose of notification, you will create a new system configuration tab.
app/code/community/Example/Affiliate/etc/system.xml
Paste the following code in this path
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<!-- we are defining a new tab -->
<tabs>
<!-- our tab unique short name -->
<Example>
<!-- the title of our tab in the admin panel sidebar -->
<label>Example Magazine</label>
<!-- the order our tab should appear on the sidebar -->
<sort_order>100</sort_order>
</Example>
</tabs>
</config>
Now, create a new file app/code/community/Example/Affiliate/etc/adminhtml.xml to configure
ACL settings
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<Example_affiliate>
<title>Example Magazine
Affiliate</title>
</Example_affiliate>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
Add the items required for new system configuration
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<tabs>
<Example>
<label>Example Magazine</label>
<sort_order>100</sort_order>
</Example>
</tabs>
<!-- we are adding a new section to our tab -->
<sections>
<!-- unique shortname for our section -->
<Example_affiliate>
<!-- the title of our section in the sidebar -->
<label>Affiliate Tracking</label>
<!-- the tab under which we want our section to appear -->
<tab>Example</tab>
<!-- order of section relative to our tab -->
<sort_order>10</sort_order>
<!-- visibility of our section -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<!-- we are adding some new groups to our section -->
<groups>
<!-- the unique short code for our group -->
<general>
<!-- the title of our group -->
<label>General Settings</label>
<!-- order of group relative to the section -->
<sort_order>10</sort_order>
<!-- visibility of our group -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<!-- we are adding some new fields to our group -->
<fields>
<!-- the unique short code for our field -->
<status>
<!-- the label of our field -->
<label>Enabled</label>
<!-- the type of our field -->
<frontend_type>select</frontend_type>
<!-- the source of our 'select' type -->
<source_model>
adminhtml/system_config_source_enabledisable
</source_model>
<!-- order relative to the group -->
<sort_order>10</sort_order>
<!-- visibility of our field -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</status>
<merchant_id>
<label>Merchant ID</label>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</merchant_id>
</fields>
</general>
<cookie>
<label>Cookie Settings</label>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<timeout>
<label>Cookie Timeout</label>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<!--
we can add a comment that
will appear below the field
-->
<comment><![CDATA[
This is the amount of time
an affiliate cookie will last, in days
]]></comment>
</timeout>
</fields>
</cookie>
</groups>
</Example_affiliate>
</sections>
</config>
Define the default admin settings using the following code
<&quest;xml version="1.0" encoding="UTF-8"&quest;>
<config>
<modules>
<Example_Affiliate>
<version>0.0.1</version>
</Example_Affiliate>
</modules>
<global>
<blocks>
<Example_affiliate>
<class>Example_Affiliate_Block</class>
</Example_affiliate>
</blocks>
<models>
<Example_affiliate>
<class>Example_Affiliate_Model</class>
</Example_affiliate>
</models>
<events>
<controller_front_init_before>
<observers>
<Example_affiliate>
<class>Example_affiliate/observer</class>
<method>captureReferral</method>
<type>singleton</type>
</Example_affiliate >
</observers>
</controller_front_init_before>
</events>
</global>
<frontend>
<layout>
<updates>
<Example_affiliate
module="Example_Affiliate">
<file>Example_affiliate.xml</file>
</Example_affiliate>
</updates>
</layout>
</frontend>
<!-- we are setting the default value -->
<default>
<!-- this is the section short name -->
<Example_affiliate>
<!-- this is the group short name -->
<cookie>
<!-- this is the field short name -->
<timeout>30</timeout>
</cookie>
</Example_affiliate>
</default>
</config>
Now, most of things required by your layout have been configured. Access the system configuration
values using the following snippet
<&quest;php $value = Mage::getStoreConfig('system/config/path'); &quest;>
Make sure you change the default system configuration path with the new one
You can now replace the hard coded cookie lifetime value with the admin panel system
configuration value
<&quest;php
class Example_Affiliate_Model_Observer
{
const COOKIE_KEY_SOURCE = 'Example_affiliate_source';
public function captureReferral(Varien_Event_Observer $observer)
{
$frontController = $observer->getEvent()->getFront();
$utmSource = $frontController->getRequest()
->getParam('utm_source', false);
if ($utmSource) {
Mage::getModel('core/cookie')->set(
self::COOKIE_KEY_SOURCE,
$utmSource,
$this->_getCookieLifetime()
);
}
}
protected function _getCookieLifetime()
{
$days = Mage::getStoreConfig(
'Example_affiliate/cookie/timeout'
);
// convert to seconds
return (int)86400 * $days;
}
}
It’s time to call the merchant ID of the affiliate to the layout defined
<&quest;php
class Example_Affiliate_Block_Conversion
extends Mage_Core_Block_Template
{
public function getIsActive()
{
return Mage::getStoreConfig(
'Example_affiliate/general/status'
) &quest; true : false;
}
public function getMerchantId()
{
return Mage::getStoreConfig(
'Example_affiliate/general/merchant_id'
);
}
public function getAffiliateId()
{
return Mage::getModel('core/cookie')->get(
Example_Affiliate_Model_Observer::COOKIE_KEY_SOURCE
);
}
}
You can easily enable or disable this new configuration system tab conversion.phtml with this code.
This way it will be called only when the checkout has been a success
<&quest;php if ($this->getIsActive()): &quest;>
<img
src="http://media.Example.com/themes/Examplev4/images/logo.png
&quest;merchant_id=<&quest;php echo $this->getMerchantId() &quest;>
&affiliate_id=<&quest;php echo $this->getAffiliateId() &quest;>"
width="1"
height="1"
/>
<&quest;php endif; &quest;>
Conclusion
It is important to create and structure community modules in the admin panel so that you can
easily use it across websites. To customize, you just need to fine tune the code to suit requirements.
Note: Don’t forget to take a backup of your system configuration and other existing files before you
create the module using this code
Original Source:
https://medium.com/@semaphoresoftware/how-to-create-module-to-track-affiliate-conversions-
20749a696ced

More Related Content

What's hot

Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueSagar Arlekar
 
Subscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSubscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSamuel Sharaf
 
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)NHN FORWARD
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!NHN FORWARD
 
Hands on SPA development
Hands on SPA developmentHands on SPA development
Hands on SPA developmentShawn Constance
 
實戰Facebook Marketing API
實戰Facebook Marketing API實戰Facebook Marketing API
實戰Facebook Marketing APIYu LI
 
Facebook广告API 101
Facebook广告API 101Facebook广告API 101
Facebook广告API 101Yu LI
 

What's hot (9)

Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
 
Subscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-finalSubscribed zuora forsalesforce training -section301-final
Subscribed zuora forsalesforce training -section301-final
 
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!
 
Hands on SPA development
Hands on SPA developmentHands on SPA development
Hands on SPA development
 
實戰Facebook Marketing API
實戰Facebook Marketing API實戰Facebook Marketing API
實戰Facebook Marketing API
 
Layout
LayoutLayout
Layout
 
Facebook广告API 101
Facebook广告API 101Facebook广告API 101
Facebook广告API 101
 
Presenters in Rails
Presenters in RailsPresenters in Rails
Presenters in Rails
 

Viewers also liked

Flyer CNAM VAE
Flyer CNAM VAEFlyer CNAM VAE
Flyer CNAM VAEcpe-c2r
 
Testimonial from Ronnie Verhelst
Testimonial from Ronnie VerhelstTestimonial from Ronnie Verhelst
Testimonial from Ronnie VerhelstJulian Dilley
 
O Manual Para Turnês Independentes
O Manual Para Turnês IndependentesO Manual Para Turnês Independentes
O Manual Para Turnês IndependentesMarco Niz
 
Thermomix Brochure TM5
Thermomix Brochure TM5Thermomix Brochure TM5
Thermomix Brochure TM5Teresa Sawyer
 
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...eaquals
 
Does Your Festival or Event Make Cent$
Does Your Festival or Event Make Cent$Does Your Festival or Event Make Cent$
Does Your Festival or Event Make Cent$Sarah Page
 
Brussels document en_presentation
Brussels document en_presentationBrussels document en_presentation
Brussels document en_presentationManuel PAOLILLO
 
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...Construir la Integración Regional desde la Cooperación Comercial y el Comerci...
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...FAO
 

Viewers also liked (9)

Flyer CNAM VAE
Flyer CNAM VAEFlyer CNAM VAE
Flyer CNAM VAE
 
Testimonial from Ronnie Verhelst
Testimonial from Ronnie VerhelstTestimonial from Ronnie Verhelst
Testimonial from Ronnie Verhelst
 
O Manual Para Turnês Independentes
O Manual Para Turnês IndependentesO Manual Para Turnês Independentes
O Manual Para Turnês Independentes
 
JURNAL ANAK
JURNAL ANAKJURNAL ANAK
JURNAL ANAK
 
Thermomix Brochure TM5
Thermomix Brochure TM5Thermomix Brochure TM5
Thermomix Brochure TM5
 
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...
Nikolay Markov Nikolov: The way to go – acting students, directing teachers, ...
 
Does Your Festival or Event Make Cent$
Does Your Festival or Event Make Cent$Does Your Festival or Event Make Cent$
Does Your Festival or Event Make Cent$
 
Brussels document en_presentation
Brussels document en_presentationBrussels document en_presentation
Brussels document en_presentation
 
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...Construir la Integración Regional desde la Cooperación Comercial y el Comerci...
Construir la Integración Regional desde la Cooperación Comercial y el Comerci...
 

Similar to How to Create Module to Track Affiliate Conversions?

Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Compare Infobase Limited
 
Affiliate Management Platform
Affiliate Management  Platform Affiliate Management  Platform
Affiliate Management Platform Sudhi Ranjan Das
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento Ravi Mehrotra
 
Quick View For Magento 2
Quick View For Magento 2 Quick View For Magento 2
Quick View For Magento 2 MageAnts
 
Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experienceBeth Soderberg
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionLitExtension
 
How to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionHow to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionLitExtension
 
Secure mvc application saineshwar
Secure mvc application   saineshwarSecure mvc application   saineshwar
Secure mvc application saineshwarSaineshwar bageri
 
Jet Magento Integration by CedCommerce
Jet Magento Integration by CedCommerceJet Magento Integration by CedCommerce
Jet Magento Integration by CedCommerceCedCommerce
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationnitin2517
 
Kentico 8 EMS API Deep Dive
Kentico 8 EMS API Deep DiveKentico 8 EMS API Deep Dive
Kentico 8 EMS API Deep DiveBrian McKeiver
 
Magento Imagine eCommerce Conference 2011: Using Magento's Import Module
Magento Imagine eCommerce Conference 2011: Using Magento's Import ModuleMagento Imagine eCommerce Conference 2011: Using Magento's Import Module
Magento Imagine eCommerce Conference 2011: Using Magento's Import Modulevarien
 
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...MagentoImagine
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Similar to How to Create Module to Track Affiliate Conversions? (20)

Magento Indexes
Magento IndexesMagento Indexes
Magento Indexes
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Affiliate Management Platform
Affiliate Management  Platform Affiliate Management  Platform
Affiliate Management Platform
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
E-Bazaar
E-BazaarE-Bazaar
E-Bazaar
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
Mangento
MangentoMangento
Mangento
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Quick View For Magento 2
Quick View For Magento 2 Quick View For Magento 2
Quick View For Magento 2
 
Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experience
 
How to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtensionHow to migrate data from Marketpress to Magento by LitExtension
How to migrate data from Marketpress to Magento by LitExtension
 
How to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtensionHow to migrate data from AmeriCommerce to Magento by LitExtension
How to migrate data from AmeriCommerce to Magento by LitExtension
 
Secure mvc application saineshwar
Secure mvc application   saineshwarSecure mvc application   saineshwar
Secure mvc application saineshwar
 
Jet Magento Integration by CedCommerce
Jet Magento Integration by CedCommerceJet Magento Integration by CedCommerce
Jet Magento Integration by CedCommerce
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementation
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Kentico 8 EMS API Deep Dive
Kentico 8 EMS API Deep DiveKentico 8 EMS API Deep Dive
Kentico 8 EMS API Deep Dive
 
Magento Imagine eCommerce Conference 2011: Using Magento's Import Module
Magento Imagine eCommerce Conference 2011: Using Magento's Import ModuleMagento Imagine eCommerce Conference 2011: Using Magento's Import Module
Magento Imagine eCommerce Conference 2011: Using Magento's Import Module
 
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
Magento's Imagine eCommerce Conference 2011 - Import Export in a Flash with t...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 

How to Create Module to Track Affiliate Conversions?

  • 1. How to Create Module to Track Affiliate Conversions? Do you or the affiliate marketer know which conversions have been made by you, and which conversions are made through the affiliate referrals? Do you inform your affiliate whenever a conversion is made through their referral? Instead of keeping track manually, Magento allows you to create a module that will track affiliate referrals and notify whenever the referral is converted. The Pre-requisites By now you must be aware with the basics of Magento and coding. You must have familiarized yourself with creating Magento modules. Whenever you are making certain website specific settings, you would add them as configurable options in the admin panel. That’s why the module you are coding for affiliate conversions will become a community module and will be stored in the following path app/code/community. When you create a community module or code, you are actually allowing future use of the module, as it is, without any modifications. To create a module to track affiliate conversions, you will need to create empty file structures containing empty files Here’s a code that will help you create this structure app - code - community - Affiliate - Block - Conversion.php - Model - Observer.php - etc
  • 2. - config.xml - design - frontend - base - default - layout - Example_affiliate.xml - template - Example_affiliate - conversion.phtml - etc - modules - Example_Affiliate.xml To add content for the example module, here is the code <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config> <modules> <Example_Affiliate> <active>true</active> <codePool>community</codePool> </Example_Affiliate> </modules> </config> Steps to Track the Affiliate Referral When you set out to track affiliates, the first thing you track is the content that referred your website. Was it a website, a newsletter, or similar kind of content that included your website details? You will also need to know the affiliate ID to reward the affiliate once the conversion has been made Example.com/&quest;utm_source=some_affiliate_id The Event Observer $_GET parameter is used to fetch a particular URL and use it for affiliate marketing. It is necessary for you, as a store to include this parameter throughout your website, so that affiliates can link the page containing the product/service of interest to their readers or users. You should not bring any changes to the core. That’s why it is necessary to use event_observer that will connect with the pages and fetch the required data The single event that will be dispatched across the different parts of the website would be controller_front_init_before Let’s create a config.xml along with an observer for this particular event <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config>
  • 3. <modules> <Example_Affiliate> <version>0.0.1</version> </Example_Affiliate> </modules> <global> <models> <Example_affiliate> <class>Example_Affiliate_Model</class> </Example_affiliate> </models> <events> <controller_front_init_before> <observers> <Example_affiliate> <class>Example_affiliate/observer</class> <method>captureReferral</method> <type>singleton</type> </Example_affiliate > </observers> </controller_front_init_before> </events> </global> </config> To capture the referral the following function will be called Example_Affiliate_Model_Observer::captureReferral() It is important to add content to observer.php that you have just created so that the referral can fetch some data <&quest;php class Example_Affiliate_Model_Observer { public function captureReferral(Varien_Event_Observer $observer) { // here we add the logic to capture the referring affiliate ID } } Capturing and Saving Affiliate ID To capture the affiliate ID, the event observer that you just created controller_front_init_before will be sent out from the Magento core defined by Mage_Core_Controller_Varien_Front::init() along with a reference specified for the same class as defined in the event dispatched from app/code/core/Mage/Core/Controller/Varien/Front.php. The code snippet used to dispatch the event is Mage::dispatchEvent( 'controller_front_init_before',
  • 4. array('front' => $this) ); If you want to gain access to the core file defined by Mage_Core_Controller_Varien_Front you will need to paste the code given below to your event_observer module <&quest;php class Example_Affiliate_Model_Observer { public function captureReferral(Varien_Event_Observer $observer) { $frontController = $observer->getEvent()->getFront(); } } This controller checks and analyzes the different URLs that are passed through it. Through this, you are able to access the object. Now, you need to check for $_GET parameter within this object. The following code will help you perform the necessary action <&quest;php class Example_Affiliate_Model_Observer { public function captureReferral(Varien_Event_Observer $observer) { $frontController = $observer->getEvent()->getFront(); $utmSource = $frontController->getRequest() ->getParam('utm_source', false); if ($utmSource) { // here we will save the referrer affiliate ID } } } Here the getRequest() is used to regain the contents of Mage_Core_Controller_Request_Http instance present within the controller. This instance will possess all the requisite details related to the URL including the $_Post and $_Get parameters. Using the getParam() method, you can easily retrieve the required details. $utmsource will contain the affiliate ID referring the link Now, you know the affiliate ID. You will need to save the details so that you can reward the affiliate in case the user who has clicked the link gets converted. As you are aware, Magento has a core functionality of dealing with Cookies. You can easily use $_COOKIE to save the $utmsource for the affiliate <&quest;php class Example_Affiliate_Model_Observer { const COOKIE_KEY_SOURCE = 'Example_affiliate_source';
  • 5. public function captureReferral(Varien_Event_Observer $observer) { $frontController = $observer->getEvent()->getFront(); $utmSource = $frontController->getRequest() ->getParam('utm_source', false); if ($utmSource) { Mage::getModel('core/cookie')->set( self::COOKIE_KEY_SOURCE, $utmSource, $this->_getCookieLifetime() ); } } protected function _getCookieLifetime() { $days = 30; // convert to seconds return (int)86400 * $days; } } Constants are truly useful when you need to use the same value across locations. In this code constant COOKIE_KEY_SOURCE has been defined. With a constant, you don’t need to keep changing the code with change in values. The code _getcookielifetime() has been defined to retrieve the cookie for a lifetime. You can always define your lifetime. In this case, the number of days has been set to 30 days. Notifying the Affiliate on Conversion The above processes have allowed us to include the affiliate ID in the cookie. Let’s say the customer who has been referenced to your website has successfully checked out fromyour website. Now, you need to notify the affiliate about the conversion, and reward them. You can create event_observer and notify using the server side API. In this case, Magento layout and introduce the necessary HTML code at the bottom of the page declaring order success In order to perform this, you will need to update config.xml to introduce the different blocks and layout created for this purpose <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config> <modules> <Example_Affiliate> <version>0.0.1</version> </Example_Affiliate> </modules> <global>
  • 6. <blocks> <Example_affiliate> <class>Example_Affiliate_Block</class> </Example_affiliate> </blocks> <models> <Example_affiliate> <class>Example_Affiliate_Model</class> </Example_affiliate> </models> <events> <controller_front_init_before> <observers> <Example_affiliate> <class>Example_affiliate/observer</class> <method>captureReferral</method> <type>singleton</type> </Example_affiliate > </observers> </controller_front_init_before> </events> </global> <frontend> <layout> <updates> <Example_affiliate module="Example_Affiliate"> <file>Example_affiliate.xml</file> </Example_affiliate> </updates> </layout> </frontend> </config> Adding New Layout with Template Files and Custom Blocks You will need to modify the layout handle onepage_checkout_success. For this you will need to update the layout file Example_affiliate.xml <&quest;xml version="1.0" encoding="UTF-8"&quest;> <layout> <checkout_onepage_success> <reference name="before_body_end"> <block type="Example_affiliate/conversion" name="Example_affiliate_conversion" template="Example_affiliate/conversion.phtml" /> </reference> </checkout_onepage_success> </layout>
  • 7. Using the below code you can define a new template file. Contents for conversion.phtml will be affiliate specific. For the sake of simplicity, the code being considered here is generic <img src="http://media.Example.com/themes/Examplev4/images/logo.png &quest;merchant_id=<&quest;php echo $this->getMerchantId() &quest;> &affiliate_id=<&quest;php echo $this->getAffiliateId() &quest;>" width="1" height="1" /> Now, you need to create a custom block to enter the data <&quest;php class Example_Affiliate_Block_Conversion extends Mage_Core_Block_Template { public function getMerchantId() { return '12345'; } public function getAffiliateId() { return Mage::getModel('core/cookie')->get( Example_Affiliate_Model_Observer::COOKIE_KEY_SOURCE ); } } Next go to System>Configuration and start configuring the different elements that would be needed for each Magento instance Configuring a New System Configuration Tab For the purpose of notification, you will create a new system configuration tab. app/code/community/Example/Affiliate/etc/system.xml Paste the following code in this path <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config> <!-- we are defining a new tab --> <tabs> <!-- our tab unique short name --> <Example> <!-- the title of our tab in the admin panel sidebar --> <label>Example Magazine</label> <!-- the order our tab should appear on the sidebar --> <sort_order>100</sort_order>
  • 8. </Example> </tabs> </config> Now, create a new file app/code/community/Example/Affiliate/etc/adminhtml.xml to configure ACL settings <&quest;xml version="1.0" encoding="UTF-8"&quest;> <adminhtml> <acl> <resources> <admin> <children> <system> <children> <config> <children> <Example_affiliate> <title>Example Magazine Affiliate</title> </Example_affiliate> </children> </config> </children> </system> </children> </admin> </resources> </acl> </adminhtml> Add the items required for new system configuration <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config> <tabs> <Example> <label>Example Magazine</label> <sort_order>100</sort_order> </Example> </tabs> <!-- we are adding a new section to our tab --> <sections> <!-- unique shortname for our section --> <Example_affiliate> <!-- the title of our section in the sidebar --> <label>Affiliate Tracking</label> <!-- the tab under which we want our section to appear --> <tab>Example</tab>
  • 9. <!-- order of section relative to our tab --> <sort_order>10</sort_order> <!-- visibility of our section --> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <!-- we are adding some new groups to our section --> <groups> <!-- the unique short code for our group --> <general> <!-- the title of our group --> <label>General Settings</label> <!-- order of group relative to the section --> <sort_order>10</sort_order> <!-- visibility of our group --> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <!-- we are adding some new fields to our group --> <fields> <!-- the unique short code for our field --> <status> <!-- the label of our field --> <label>Enabled</label> <!-- the type of our field --> <frontend_type>select</frontend_type> <!-- the source of our 'select' type --> <source_model> adminhtml/system_config_source_enabledisable </source_model> <!-- order relative to the group --> <sort_order>10</sort_order> <!-- visibility of our field --> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </status> <merchant_id> <label>Merchant ID</label> <frontend_type>text</frontend_type> <sort_order>20</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </merchant_id> </fields> </general>
  • 10. <cookie> <label>Cookie Settings</label> <sort_order>20</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <fields> <timeout> <label>Cookie Timeout</label> <frontend_type>text</frontend_type> <sort_order>10</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> <!-- we can add a comment that will appear below the field --> <comment><![CDATA[ This is the amount of time an affiliate cookie will last, in days ]]></comment> </timeout> </fields> </cookie> </groups> </Example_affiliate> </sections> </config> Define the default admin settings using the following code <&quest;xml version="1.0" encoding="UTF-8"&quest;> <config> <modules> <Example_Affiliate> <version>0.0.1</version> </Example_Affiliate> </modules> <global> <blocks> <Example_affiliate> <class>Example_Affiliate_Block</class> </Example_affiliate> </blocks> <models> <Example_affiliate> <class>Example_Affiliate_Model</class> </Example_affiliate>
  • 11. </models> <events> <controller_front_init_before> <observers> <Example_affiliate> <class>Example_affiliate/observer</class> <method>captureReferral</method> <type>singleton</type> </Example_affiliate > </observers> </controller_front_init_before> </events> </global> <frontend> <layout> <updates> <Example_affiliate module="Example_Affiliate"> <file>Example_affiliate.xml</file> </Example_affiliate> </updates> </layout> </frontend> <!-- we are setting the default value --> <default> <!-- this is the section short name --> <Example_affiliate> <!-- this is the group short name --> <cookie> <!-- this is the field short name --> <timeout>30</timeout> </cookie> </Example_affiliate> </default> </config> Now, most of things required by your layout have been configured. Access the system configuration values using the following snippet <&quest;php $value = Mage::getStoreConfig('system/config/path'); &quest;> Make sure you change the default system configuration path with the new one
  • 12. You can now replace the hard coded cookie lifetime value with the admin panel system configuration value <&quest;php class Example_Affiliate_Model_Observer { const COOKIE_KEY_SOURCE = 'Example_affiliate_source'; public function captureReferral(Varien_Event_Observer $observer) { $frontController = $observer->getEvent()->getFront(); $utmSource = $frontController->getRequest() ->getParam('utm_source', false); if ($utmSource) { Mage::getModel('core/cookie')->set( self::COOKIE_KEY_SOURCE, $utmSource, $this->_getCookieLifetime() ); } } protected function _getCookieLifetime() { $days = Mage::getStoreConfig( 'Example_affiliate/cookie/timeout' ); // convert to seconds return (int)86400 * $days; } } It’s time to call the merchant ID of the affiliate to the layout defined <&quest;php class Example_Affiliate_Block_Conversion extends Mage_Core_Block_Template { public function getIsActive() { return Mage::getStoreConfig( 'Example_affiliate/general/status' ) &quest; true : false; } public function getMerchantId() { return Mage::getStoreConfig(
  • 13. 'Example_affiliate/general/merchant_id' ); } public function getAffiliateId() { return Mage::getModel('core/cookie')->get( Example_Affiliate_Model_Observer::COOKIE_KEY_SOURCE ); } } You can easily enable or disable this new configuration system tab conversion.phtml with this code. This way it will be called only when the checkout has been a success <&quest;php if ($this->getIsActive()): &quest;> <img src="http://media.Example.com/themes/Examplev4/images/logo.png &quest;merchant_id=<&quest;php echo $this->getMerchantId() &quest;> &affiliate_id=<&quest;php echo $this->getAffiliateId() &quest;>" width="1" height="1" /> <&quest;php endif; &quest;> Conclusion It is important to create and structure community modules in the admin panel so that you can easily use it across websites. To customize, you just need to fine tune the code to suit requirements. Note: Don’t forget to take a backup of your system configuration and other existing files before you create the module using this code Original Source: https://medium.com/@semaphoresoftware/how-to-create-module-to-track-affiliate-conversions- 20749a696ced