- Having 2 pages
- Choosing your groups
- Storing user clicks
- Seeing your data
Redis is likely better run on a Linux box than Windows. Although there is a Windows version it was developed largely by Microsoft and it not officially supported. At the current time there are no plans to merge the Windows support back into mainline. Still the Windows version will work just fine for development purposes. I installed Redis using ChocolateyÂ Nuget
You can do that or download the package and do it manually.
There are a couple of .net clients available for Redis but I went with one called Booksleeve which was developed by the Stackoverflow team. This can be installed from nuget
Now we need to write to Redis as needed. I created a simple interface to handle the logging.
LogInitialVisit is called whenever somebody visits and A/B page and LogSuccess is used when the user has performed the activity we want. The initial visit call can be hooked into the BaseController we created in part 1.
The actual Redis implementation of IABLogger looks like:
In a real implementation just using localhost for the Redis server is likely not what you want. What isnâ€™t apparent here is that the call to Redis is performed asynchronously inside Booksleeve so this should have very little impact on the speed of page rendering.
The initial visit counter should be correctly updated. Now we need a way to update success counter. There are a couple of approaches to this but I think the best is simply to provide an end point for the views to call out for when â€œsuccessâ€ is achieved. Success can be visiting a link or just pausing on the page for a period of time; an endpoint which accepts POSTs is sufficiently flexible to handle all eventualities.
The controller looks like
Iâ€™m a big fan to TypeScript so I wrote my client side code in TypeScript
The ready function at the end hooks up links which have appropriate data- attributes. This does mean that a post is sent to our server before sending people on to their final destination. Google does more or less the same thing with search results.
If we check the results in Redis we can see that appropriate keys have been created and values set.
redis 127.0.0.1:6379> keys About* 1) "About.AboutA.success" 2) "About.AboutB.success" 3) "About.AboutA" 4) "About.AboutB" redis 127.0.0.1:6379> get About.AboutA "8" redis 127.0.0.1:6379> get About.AboutA.success "1"
In the next part weâ€™ll look at how to retrieve and analyse the statistics weâ€™ve gathered.