Created
October 14, 2011 17:14
-
-
Save mlynch/1287710 to your computer and use it in GitHub Desktop.
MongoDB landing page conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A MongoDB query script. Example output: | |
760 landings | |
69 signups | |
Conversion rate: 9.078947368421053% | |
Campaign conversions: | |
organic: 8.042% - 53/659 | |
betabuild1: 0% - 0/6 | |
betanocodingbuilder: 37.500% - 6/16 | |
betaonlydrag: 50.000% - 2/4 | |
betaonlydragtool: 0% - 0/4 | |
betamobmin: 11.321% - 6/53 | |
*/ | |
var signups = db['beta_interest']; | |
var landings = db['landing']; | |
var landingEntries = landings.find(); | |
var signupEntries = signups.find(); | |
var landingClick = {}; | |
var signupClick = {}; | |
var campaignLandingCount = {}; | |
var campaignSignupCount = {}; | |
landingEntries.forEach(function(obj) { | |
landingClick[obj.clickId] = obj | |
if(!campaignLandingCount.hasOwnProperty(obj.campaign)) { | |
campaignLandingCount[obj.campaign] = 1; | |
} else { | |
campaignLandingCount[obj.campaign]++; | |
} | |
}); | |
signupEntries.forEach(function(obj) { | |
signupClick[obj.clickId] = obj | |
if(!campaignSignupCount.hasOwnProperty(obj.campaign)) { | |
campaignSignupCount[obj.campaign] = 1; | |
} else { | |
campaignSignupCount[obj.campaign]++; | |
} | |
}); | |
var totalLanding = landingEntries.count(); | |
var totalSignups = signupEntries.count(); | |
print(totalLanding + ' landings'); | |
print(totalSignups + ' signups'); | |
print('Conversion rate: ' + (totalSignups / totalLanding) * 100 + '%'); | |
print('Campaign conversions:'); | |
for(var campaign in campaignLandingCount) { | |
if(campaignSignupCount.hasOwnProperty(campaign)) { | |
var signups = campaignSignupCount[campaign]; | |
var landings = campaignLandingCount[campaign]; | |
var perc = (signups / landings) * 100; | |
print('\t' + campaign + ': ' + perc.toFixed(3) + '%' + ' - ' + signups + '/' + landings); | |
} else { | |
print('\t' + campaign + ': 0% - 0/' + campaignLandingCount[campaign]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment