Revert "Merge pull request #4545 from edx/renzo/bi-analytics-overhaul"

This reverts commit 252038c376, reversing
changes made to 7caf8c53b1.
This commit is contained in:
Julia Hansbrough
2014-07-29 17:41:46 +00:00
parent 4353e1e48f
commit 079808ee47
26 changed files with 58 additions and 244 deletions

View File

@@ -16,26 +16,3 @@ describe('utility.rewriteStaticLinks', function () {
).toBe('<img src="http://www.mysite.org/static/foo.x"/>')
});
});
describe('utility.appendParameter', function() {
it('creates and populates query string with provided parameter', function() {
expect(appendParameter('/cambridge', 'season', 'fall')).toBe('/cambridge?season=fall')
});
it('appends provided parameter to existing query string parameters', function() {
expect(appendParameter('/cambridge?season=fall', 'color', 'red')).toBe('/cambridge?season=fall&color=red')
});
it('appends provided parameter to existing query string with a trailing ampersand', function() {
expect(appendParameter('/cambridge?season=fall&', 'color', 'red')).toBe('/cambridge?season=fall&color=red')
});
it('overwrites existing parameter with provided value', function() {
expect(appendParameter('/cambridge?season=fall', 'season', 'winter')).toBe('/cambridge?season=winter');
expect(appendParameter('/cambridge?season=fall&color=red', 'color', 'orange')).toBe('/cambridge?season=fall&color=orange');
});
});
describe('utility.parseQueryString', function() {
it('converts a non-empty query string into a key/value object', function() {
expect(JSON.stringify(parseQueryString('season=fall'))).toBe(JSON.stringify({season:'fall'}));
expect(JSON.stringify(parseQueryString('season=fall&color=red'))).toBe(JSON.stringify({season:'fall', color:'red'}));
});
});

View File

@@ -38,129 +38,4 @@ window.rewriteStaticLinks = function(content, from, to) {
// note: add other protocols here
var regex = new RegExp("(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}([-a-zA-Z0-9@:%_\+.~#?&//=]*))?"+from, 'g');
return content.replace(regex, replacer);
};
// Appends a parameter to a path; useful for indicating initial or return signin, for example
window.appendParameter = function(path, key, value) {
// Check if the given path already contains a query string by looking for the ampersand separator
if (path.indexOf("?") > -1) {
var splitPath = path.split("?");
var parameters = window.parseQueryString(splitPath[1]);
// Check if the provided key already exists in the query string
if (key in parameters) {
// Overwrite the existing key's value with the provided value
parameters[key] = value;
// Reconstruct the path, including the overwritten key/value pair
var reconstructedPath = splitPath[0] + "?";
for (var k in parameters) {
reconstructedPath = reconstructedPath + k + "=" + parameters[k] + "&";
}
// Strip the trailing ampersand
return reconstructedPath.slice(0, -1);
} else {
// Check for a trailing ampersand
if (path[path.length - 1] != "&") {
// Append signin parameter to the existing query string
return path + "&" + key + "=" + value;
} else {
// Append signin parameter to the existing query string, excluding the ampersand
return path + key + "=" + value;
}
}
} else {
// Append new query string containing the provided parameter
return path + "?" + key + "=" + value;
}
};
// Convert a query string to a key/value object
window.parseQueryString = function(queryString) {
var parameters = {}, queries, pair, i, l;
// Split the query string into key/value pairs
queries = queryString.split("&");
// Break the array of strings into an object
for (i = 0, l = queries.length; i < l; i++) {
pair = queries[i].split('=');
parameters[pair[0]] = pair[1];
}
return parameters
};
// Check if the user recently enrolled in a course by looking at a referral URL
window.checkRecentEnrollment = function(referrer) {
var enrolledIn = null;
// Check if the referrer URL contains a query string
if (referrer.indexOf("?") > -1) {
referrerQueryString = referrer.split("?")[1];
} else {
referrerQueryString = "";
}
if (referrerQueryString != "") {
// Convert a non-empty query string into a key/value object
var referrerParameters = window.parseQueryString(referrerQueryString);
if ("course_id" in referrerParameters && "enrollment_action" in referrerParameters) {
if (referrerParameters.enrollment_action == "enroll") {
enrolledIn = referrerParameters.course_id;
}
}
}
return enrolledIn
};
window.assessUserSignIn = function(parameters, userID, email, username) {
// Check if the user has logged in to enroll in a course - designed for when "Register" button registers users on click (currently, this could indicate a course registration when there may not have yet been one)
var enrolledIn = window.checkRecentEnrollment(document.referrer);
// Check if the user has just registered
if (parameters.signin == "initial") {
window.trackAccountRegistration(enrolledIn, userID, email, username);
} else {
window.trackReturningUserSignIn(enrolledIn, userID, email, username);
}
};
window.trackAccountRegistration = function(enrolledIn, userID, email, username) {
// Alias the user's anonymous history with the user's new identity (for Mixpanel)
analytics.alias(userID);
// Map the user's activity to their newly assigned ID
analytics.identify(userID, {
email: email,
username: username
});
// Track the user's account creation
analytics.track("edx.bi.user.account.registered", {
category: "conversion",
label: enrolledIn != null ? enrolledIn : "none"
});
};
window.trackReturningUserSignIn = function(enrolledIn, userID, email, username) {
// Map the user's activity to their assigned ID
analytics.identify(userID, {
email: email,
username: username
});
// Track the user's sign in
analytics.track("edx.bi.user.account.authenticated", {
category: "conversion",
label: enrolledIn != null ? enrolledIn : "none"
});
};
window.identifyUser = function(userID, email, username) {
// If the signin parameter isn't present but the query string is non-empty, map the user's activity to their assigned ID
analytics.identify(userID, {
email: email,
username: username
});
};
};