Question

I'm working on a affiliate system in grails where users can create individual links and guests who are visiting this links get an cookie with an unique session id. If some of the guests come a few days later to my webApp again i want to know that they've been here already and wich user brought this guest to my website in the past.

How would you implement this in grails? I would say with filters. But how should i implement such a filter? Using the grails default session id wouldn't be good, because it gets invalidated and i can't upgrade the grails session lifetime as much because of the servers memory (RAM). Or is the sessionId always there and gets only refreshed, so the session lifetime in grails could be 1 hour and i'm able to track everything longer than an hour too?

Or should i set a new cookie with a unique session id especially for my purpose?

Was it helpful?

Solution

You probably need at least one filter and one cookie.

When the visitor comes to your site for the first time, I'm imagining that you define the affiliate ID as a request parameter. You probably need to create a before filter to see if the visitor already has a cookie set.

If you're just trying to associate sales with an affiliate then you don't need a unique visitor ID, just the affiliate ID that referred the visitor. Inside your filter, if the affiliate ID request parameter is present but there is no cookie, you can set the cookie. Then, when you are processing a sale, you can check if the affiliate cookie exists.

If you are trying to get more advanced metrics then you probably will need two filters (or one filter that does 2 things). One to set the cookie, and one to track the visit. Once you know the things you want to track, you can also put flag's in the user's session to keep your metrics accurate (i.e. if you don't consider each request a visit you may want to put a flag in the user's session after you increment the number of visits for the visitor.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top