* VRFS-709 - registrations tracked

This commit is contained in:
Seth Call 2013-09-23 21:00:39 +00:00
parent 5bbea091bb
commit 3c69988d1d
13 changed files with 137 additions and 39 deletions

View File

@ -16,5 +16,6 @@
//= require jquery.cookie
//= require jquery.Jcrop
//= require jquery.naturalsize
//= require jquery.queryparams
//= require bootstrap
//= require_directory .

View File

@ -1,7 +1,9 @@
//= require jquery
//= require jquery.queryparams
//= require AAC_underscore
//= require jamkazam
//= require utils
//= require ga
//= require jam_rest
//= require corp/init
//= require_directory ../corp

View File

@ -0,0 +1,54 @@
/**
* Common utility functions.
*/
(function(context,$) {
"use strict";
context.JK = context.JK || {};
var logger = context.JK.logger;
// types
var registrationTypes = {
native : "Native",
facebook : "Facebook"
}
var categories = {
register : "Register"
}
function assertBoolean(value) {
if(typeof value != 'boolean') {
throw "value is not a boolean: " + JSON.stringify(value);
}
}
function assertOneOf(enumValue, enums){
var found = false;
for (var key in enums) {
if (enumValue == enums[key]) {
found = true;
break;
}
}
if(!found) {
throw "unable to find enum: " + enumValue + " in: " + JSON.stringify(enums);
}
}
function trackRegister(asMusician, registrationType) {
assertBoolean(asMusician);
assertOneOf(registrationType, registrationTypes);
var action = asMusician ? "Musician" : "Fan";
ga('send', 'event', categories.register, action, registrationType);
}
var GA = {};
GA.trackRegister = trackRegister;
context.JK.GA = GA;
})(window,jQuery);

View File

@ -0,0 +1,14 @@
// from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values
(function($) {
$.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'))
})(jQuery);

View File

@ -4,56 +4,68 @@
var congratulations = {};
congratulations.initialize = function initialize() {
function listClients() {
var rest = context.JK.Rest();
var currentOS = context.JK.detectOS();
var downloads = $('.downloads');
rest.getClientDownloads()
.done(function(data) {
downloads.removeClass('spinner-large');
.done(function(data) {
downloads.removeClass('spinner-large');
var count = 0;
for ( var property in data ) count++;
var count = 0;
for ( var property in data ) count++;
if(count == 0) {
alert("Currently unable to list client software downloads.");
}
else {
if(count == 0) {
alert("Currently unable to list client software downloads.");
}
else {
$.each(data, function(key, item) {
$.each(data, function(key, item) {
// if the currentOS we detect from browser is found within the product of an available client
// we flag it with this boolean
var matchesUserOS = currentOS != null && key.toLowerCase().indexOf(currentOS.toLowerCase()) > -1;
// if the currentOS we detect from browser is found within the product of an available client
// we flag it with this boolean
var matchesUserOS = currentOS != null && key.toLowerCase().indexOf(currentOS.toLowerCase()) > -1;
var options = {
emphasis: matchesUserOS ? "currentOS" : "",
uri: item.uri,
platform: key.substring('JamClient/'.length)
}
var options = {
emphasis: matchesUserOS ? "currentOS" : "",
uri: item.uri,
platform: key.substring('JamClient/'.length)
}
var download = context._.template($('#client-download-link').html(), options, {variable: 'data'});
var download = context._.template($('#client-download-link').html(), options, {variable: 'data'});
if(matchesUserOS) {
// make sure the current user OS is at the top
downloads.prepend(download);
}
else {
downloads.append(download)
}
});
}
})
.fail(function() {
downloads.removeClass('spinner-large');
alert("Currently unable to list client software downloads due to error.");
})
if(matchesUserOS) {
// make sure the current user OS is at the top
downloads.prepend(download);
}
else {
downloads.append(download)
}
});
}
})
.fail(function() {
downloads.removeClass('spinner-large');
alert("Currently unable to list client software downloads due to error.");
})
}
congratulations.initialize = function initialize(musician, registrationType) {
if(musician) {
listClients();
}
if(registrationType) {
$(function() {
// ga() object isn't ready until the page is loaded
context.JK.GA.trackRegister(musician, registrationType);
});
}
}
window.congratulations = congratulations;
context.congratulations = congratulations;
})(window, jQuery)

View File

@ -1,7 +1,9 @@
//= require jquery
//= require jquery.queryparams
//= require AAC_underscore
//= require jamkazam
//= require utils
//= require ga
//= require jam_rest
//= require landing/init
//= require landing/signup

View File

@ -92,9 +92,9 @@ class UsersController < ApplicationController
sign_in @user
if @user.musician
redirect_to :congratulations_musician
redirect_to :action => :congratulations_musician, :type => 'Native'
else
redirect_to :congratulations_fan
redirect_to :action => :congratulations_fan, :type => 'Native'
end
end

View File

@ -1,4 +1,4 @@
<% if current_user.nil? || !current_user.admin? # remove admin users from GA %>
<% if current_user.nil? || !Rails.application.config.ga_suppress_admin || !current_user.admin? # remove admin users from GA %>
<script>
(function(context) {
if(context.jamClient) {

View File

@ -17,4 +17,8 @@
<div align="center"><%= link_to "PROCEED TO JAMKAZAM SITE", root_path, :class =>"button-orange m0" %></div>
</div>
<!-- end inner -->
</div>
</div>
<script type="text/javascript">
window.congratulations.initialize(false, jQuery.QueryString["type"]);
</script>

View File

@ -24,7 +24,7 @@
<script type="text/javascript">
window.congratulations.initialize();
window.congratulations.initialize(true, jQuery.QueryString["type"]);
</script>
<script type="text/template" id="client-download-link">

View File

@ -153,5 +153,6 @@ if defined?(Bundler)
config.bugsnag_notify_release_stages = ["production"] # add 'development' if you want to test a bugsnag feature locally
config.ga_ua = 'UA-44184562-2' # google analytics
config.ga_suppress_admin = true
end
end

View File

@ -48,4 +48,7 @@ SampleApp::Application.configure do
# this is totally awful and silly; the reason this exists is so that if you upload an artifact
# through jam-admin, then jam-web can point users at it. I think 99% of devs won't even see or care about this config, and 0% of users
config.jam_admin_root_url = 'http://192.168.1.152:3333'
# it's nice to have even admin accounts (which all the default ones are) generate GA data for testing
config.ga_suppress_admin = false
end

View File

@ -32,6 +32,7 @@ describe "Signup" do
it { User.find_by_email('noone@jamkazam.com').musician_instruments.length.should == 1 }
# an email is sent on no-invite signup
it { UserMailer.deliveries.length.should == 1 }
it {uri = URI.parse(current_url); "#{uri.path}?#{uri.query}".should == congratulations_musician_path(:type => 'Native')}
end
describe "with valid fan information" do
@ -54,6 +55,7 @@ describe "Signup" do
it { User.find_by_email('somefan@jamkazam.com').musician_instruments.length.should == 0 }
# an email is sent on no-invite signup
it { UserMailer.deliveries.length.should == 1 }
it {uri = URI.parse(current_url); "#{uri.path}?#{uri.query}".should == congratulations_fan_path(:type => 'Native')}
end
describe "with service invite" do
@ -78,6 +80,7 @@ describe "Signup" do
# there is no email sent though when you signup based on an invite (because you just left your email to get here)
it { UserMailer.deliveries.length.should == 0 }
it {uri = URI.parse(current_url); "#{uri.path}?#{uri.query}".should == congratulations_musician_path(:type => 'Native')}
end
describe "with user invite and autofriend" do
@ -101,6 +104,7 @@ describe "Signup" do
it { should have_selector('h1', text: "congratulations") }
it { @user.friends?(User.find_by_email("noone@jamkazam.com")) }
it { User.find_by_email("noone@jamkazam.com").friends?(@user) }
it {uri = URI.parse(current_url); "#{uri.path}?#{uri.query}".should == congratulations_musician_path(:type => 'Native')}
end
describe "can't signup to the same invite twice" do
@ -148,6 +152,7 @@ describe "Signup" do
it { User.find_by_email('what@jamkazam.com').should be_nil }
# an email is sent when you invite but use a different email than the one used to invite
it { UserMailer.deliveries.length.should == 1 }
it {uri = URI.parse(current_url); "#{uri.path}?#{uri.query}".should == congratulations_musician_path(:type => 'Native')}
it {
visit "#{signup_path}?invitation_code=#{@invited_user.invitation_code}"
should have_selector('h1', text: "You have already signed up with this invitation")