Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Affiliate Links to my web application?

I have built a web application using Java EE platform that sells one of my software.

Now I want to give the work of marketing my website to various e-marketing companies. But as I will have to give the commission to them, I should know that who sends the traffic.

I think that one solution to above problem is:

Make a separate URL for each e-marketing company and give them their corresponding URL and redirect all those URLs to a single Servlet. And after that, count the no. of visitors on a particular URL (url of an e-marketing company) to count the no. of visitors referred by that e-marketing company.

The Google and various other use similar kinds of techniques which distinguishes one from other.

Q1. Do all of them uses this kind of approach?

Q2. Is there any other approach by which this can be done in a much better way?

You can also advice some other things too...

Thanks in advance

like image 597
Yatendra Avatar asked Feb 22 '10 18:02

Yatendra


2 Answers

You could use a Query String parameter, too. (This may be what krassib was referring to.) Like http://yoursite.foo/yourpage.jsp?affiliateid=ABC123

Then just have that single page parse the querystring from the URL and store/count that.

like image 78
TomR Avatar answered Nov 08 '22 06:11

TomR


Yep i agree with @krassib and @TomR - use a queryString parameter, then you can write a servlet filter to check for the specific paramater and increment the count for that affiliate. Using a servlet filter would also give you the added bonus of being to track the count of individual links on a per affiliate basis.

You do something like the following:

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class AffiliateTrackingFilter implements Filter {
    private AffiliateTrackingService affiliateTrackingService = null;

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest rq, ServletResponse rs,
            FilterChain chain) throws IOException, ServletException {
        String affililateId = rq.getParameter("affiliateId");
        affiliateTrackingService.incrementAffiliateHit(affililateId);
        chain.doFilter();
    }

    @Override
    public void init(FilterConfig fc) throws ServletException {
        affiliateTrackingService = new AffiliateTrackingService();
    }
}

Then add something like this to your web.xml:

<filter>
    <filter-name>AffiliateTrackingFilter</filter-name>
    <filter-class>com.example.AffiliateTrackingFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>AffiliateTrackingFilter</filter-name>
    <servlet-name>MyMainServlet</servlet-name>
</filter-mapping>

And have a filter mapping for all of your servlets.

like image 28
simonlord Avatar answered Nov 08 '22 06:11

simonlord