Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ language: ruby
rvm:
- 2.2.3
before_install: gem install bundler -v 1.11.2
script: rake travis
6 changes: 6 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
# * zeus: 'zeus rspec' (requires the server to be started separately)
# * 'just' rspec: 'rspec'

guard 'jasmine' do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
end

guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
Expand Down
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ RSpec::Core::RakeTask.new(:spec)
task :default => :spec
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'

task :travis do
["rspec spec", "rake jasmine:ci"].each do |cmd|
puts "Starting to run #{cmd}..."
system("export DISPLAY=:99.0 && bundle exec #{cmd}")
raise "#{cmd} failed!" unless $?.exitstatus == 0
end
end
2 changes: 2 additions & 0 deletions action_tracker.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'guard', '~> 2.13'
spec.add_development_dependency 'byebug', '~> 5.0'
spec.add_development_dependency 'guard-rspec', '~> 4.6'
spec.add_development_dependency 'guard-jasmine', '~> 2.0.6'

spec.add_development_dependency 'jasmine', '~> 2.4'
end
69 changes: 69 additions & 0 deletions app/assets/javascripts/Storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var ActionTracker = (function(self) {

self.Storage = function() {
var storage = [];

function constructor() {
if(sessionStorage.getItem('action_tracker_storage')) {
getStorage();
} else {
setStorage();
}
}

function getStorage() {
storage = JSON.parse(sessionStorage.getItem('action_tracker_storage'));
}

function setStorage() {
sessionStorage.setItem('action_tracker_storage', JSON.stringify(storage));
}

function queue(list) {
if(list !== null) {
getStorage();
var i;
for (i = 0; i < list.length; i += 1) {
storage.push(list[i]);
}
setStorage();
}
}

function dequeue() {
getStorage();
var first = storage[0];
storage.splice(0, 1);
setStorage();
return first;
}

function getFirst() {
getStorage();
return storage[0];
}

function clear() {
storage = [];
setStorage();
}

function getLocalStorage() {
return storage;
}

constructor();

return {
queue: queue,
dequeue: dequeue,
getStorage: getLocalStorage,
getFirst: getFirst,
refreshStorage: getStorage,
clear: clear,
};
};

return self;

}(ActionTracker || {}));
17 changes: 17 additions & 0 deletions app/assets/javascripts/TimeSeed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var ActionTracker = (function(self) {
self.TimeSeed = function() {
var seedDate = new Date();

function getTimeSeed() {
seedDate.setSeconds(seedDate.getSeconds() + 1);
return seedDate;
}

return {
getTimeSeed: getTimeSeed
};
};

return self;

}(ActionTracker || {}));
52 changes: 52 additions & 0 deletions app/assets/javascripts/Tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var ActionTracker = (function(self) {

self.Tracker = function(trackerData, cfgOptions, callbacks) {
var userFlag = false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'userFlag' is defined but never used.

user = null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'user' is defined but never used.

options = null,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'options' is defined but never used.

data = null,
dataFlag = false,
logoutFlag = false;

if(typeof cfgOptions !== 'undefined') {
options = cfgOptions;
}

if(typeof trackerData !== 'undefined') {
if(typeof trackerData.identify !== 'undefined') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'trackerData' is not defined.

userFlag = true;
user = new self.User(trackerData.identify, callbacks);
}
if(typeof trackerData.track !== 'undefined') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'trackerData' is not defined.

dataFlag = true;
data = trackerData.track;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'trackerData' is not defined.

if(options.timestamp) {
data.created_at = options.seed.getTimeSeed();
}
}
if(trackerData.logout) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'trackerData' is not defined.

logoutFlag = true;
}
}

function send() {
if(userFlag) {
callbacks.identify(user.getData());
}
if(dataFlag) {
callbacks.track(data, function() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'callbacks' is not defined.

if(logoutFlag) {
callbacks.logout();
}
});
}
}

return {
send: send
};
};

return self;

}(ActionTracker || {}));
25 changes: 25 additions & 0 deletions app/assets/javascripts/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var ActionTracker = (function(self) {

self.User = function(userData, userCallbacks) {
var data = userData,
callbacks = userCallbacks;

data.id = callbacks.generateID(data.email);

function getData() {
return data;
}

function getCallbacks() {
return callbacks;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.


return {
getData: getData,
getCallbacks: getCallbacks
};
};

return self;

}(ActionTracker || {}));
151 changes: 18 additions & 133 deletions app/assets/javascripts/action_tracker.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
//= require Storage
//= require TimeSeed
//= require User
//= require Tracker

var ActionTracker = function () {

'use strict';
var ActionTracker = (function(self) {

var storage,
timeSeed,
options = {},
callbacks = {};

function constructor() {
storage = new Storage();
timeSeed = new TimeSeed();
}

function setCallbacks(callbacksObj) {
self.callbacks = function(callbacksObj) {
callbacks = callbacksObj;
}
};

function start(list, cfgOptions) {
self.new = function(list, cfgOptions) {
if(typeof cfgOptions !== 'undefined') {
options = cfgOptions;
}
storage.queue(list);
}
};

function process() {
self.push = function() {
var tracker;
while(typeof storage.getFirst() !== 'undefined') {
tracker = new Tracker(storage.dequeue(), trackerOptions());
tracker = new self.Tracker(storage.dequeue(), trackerOptions(), callbacks);
tracker.send();
}
};

function constructor() {
storage = new self.Storage();
timeSeed = new self.TimeSeed();
}

function trackerOptions() {
Expand All @@ -41,125 +43,8 @@ var ActionTracker = function () {
return trackerParams;
}

function Storage() {

this.storage = [];

this.constructor = function() {
if(sessionStorage.getItem('action_tracker_storage')) {
this.getStorage();
} else {
this.setStorage();
}
};

this.getStorage = function() {
this.storage = JSON.parse(sessionStorage.getItem('action_tracker_storage'));
};

this.setStorage = function() {
sessionStorage.setItem('action_tracker_storage', JSON.stringify(this.storage));
};

this.queue = function(list) {
if(list != null) {
this.getStorage();
var i;
for (i = 0; i < list.length; i += 1) {
this.storage.push(list[i]);
}
this.setStorage();
}
};

this.dequeue = function() {
this.getStorage();
var first = this.storage[0];
this.storage.splice(0, 1);
this.setStorage();
return first;
};

this.getFirst = function() {
this.getStorage();
return this.storage[0];
};

this.constructor();
}

function Tracker(trackerData, cfgOptions) {

this.userFlag = false;
this.user = null;
this.options = null;

var data = null;
var dataFlag = false;
var logoutFlag = false;

if(typeof cfgOptions !== 'undefined') {
this.options = cfgOptions;
}

if(typeof trackerData !== 'undefined') {
if(typeof trackerData.identify !== 'undefined') {
this.userFlag = true;
this.user = new User(trackerData.identify);
}
if(typeof trackerData.track !== 'undefined') {
dataFlag = true;
data = trackerData.track;
if(this.options.timestamp) {
data.created_at = this.options.seed.getTimeSeed();
}
}
if(trackerData.logout) {
logoutFlag = true;
}
}

this.send = function() {
if(this.userFlag) {
callbacks.identify(this.user.getData());
}
if(dataFlag) {
callbacks.track(data, function() {
if(logoutFlag) {
callbacks.logout();
}
});
}
};
}

function User(userData) {
this.data = userData;
this.data.id = callbacks.generateID(this.data.email);

this.getData = function() {
return this.data;
};
}

function TimeSeed() {
this.seed_date = new Date();

this.getTimeSeed = function() {
this.seed_date.setSeconds(this.seed_date.getSeconds() + 1);
return this.seed_date;
};
}

constructor();

return {
Tracker: Tracker,
User: User,
Storage: Storage,
new: start,
push: process,
callbacks: setCallbacks
};
return self;

}();
}(ActionTracker || {}));
Loading