(function() {
	MSGI.namespace('MSGI.promo');
	
	/**
	 * Track an action made by a user who was referred to the site by a promotion.
	 * @param action {string} currently either "click" (user hits home page) or "signup" (user completes registration)
	 * @param channel {number} ID of the channel to which the user was referred
	 * @param promo {string} the promo code to track, provided to MSGI as a URL variable
	 * @param callback {function} optional callback function called after the promo has been tracked
	 */
	MSGI.promo.track = function(action, channel, promo, callback) {
		MSGI.service.send('promotion_track', {
			'channel_id': channel, 
			'promo_code': promo, 
			'type': action
		}, callback || function() {});
	};
	
	/**
	 * Get an aggregate report of promo actions tracked to date
	 * @param callback {function} the callback function takes an array of stats
	 */
	MSGI.promo.stats = function(callback) {
		MSGI.service.send('promotion_getStats', function(response) {
			if (response.error) throw(response.error.message || response.error.toString());
			callback(response.result);
		});
	}	
})();

