You would generally need two dataset. I .e transaction id & product as first & visitorID & productsviewed as second to arrive at a % of confidence of having any two products being sold(or viewed) together. You can use R (statistic software) & install a package called "arules" to generate these recommendations easily.
Here is a sample code that you may want to check out in R
setwd(“C:/Documents and Settings/rp/Desktop/output”);
install.packages(“arules”);
library(“arules”);
txn = read.transactions(file=”Transactions_sample.csv”, rm.duplicates= FALSE, format=”single”,sep=”,”,cols =c(1,2));
basket_rules <- apriori(txn,parameter = list(sup = 0.5, conf = 0.9,target=”rules”));
inspect(basket_rules);
If you would really want to understand how it works, you may want to check out the white paper at http://www.tatvic.com/resources named as product purchase pattern analysis which indicates how you can do it simply with your web data.
Further, if you want to use a readymade API for it, it is available at http://www.liftsuggest.com/how-lift-product-recommendation-works