referrer_tracker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +21 -0
- data/Rakefile +35 -0
- data/init.rb +13 -0
- data/install.rb +1 -0
- data/lib/app/models/track.rb +3 -0
- data/lib/db/migrate/20110523140707_create_referrer_track_model.rb +14 -0
- data/lib/db/schema.rb +0 -0
- data/lib/referrer_tracker/utils.rb +102 -0
- data/lib/referrer_tracker.rb +34 -0
- data/lib/tasks/set_up.rake +29 -0
- data/referrer_tracker.gemspec +50 -0
- data/test/old_referrer_tracker.rb +86 -0
- data/test/referrer_tracker_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +82 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
ReferrerTracker
|
2
|
+
===============
|
3
|
+
|
4
|
+
This plugin tracks the source of the traffic for you and also tracks the conversations happening in your rails project.
|
5
|
+
|
6
|
+
Example
|
7
|
+
=======
|
8
|
+
|
9
|
+
In referrer_tracker.yml file in cofig directory -
|
10
|
+
|
11
|
+
track1:
|
12
|
+
start_action: "home", "index" #This will set landingpage.
|
13
|
+
end_action: "user", "create" #This will be action of successfull conversion. user signup in this case.
|
14
|
+
conversion: true #if set to true, this will track the conversions.
|
15
|
+
conversion_rate: true #if set to true, this will also save landingpage hits, based on which conversion_rate can be calculated.
|
16
|
+
referreral_parameter: sr # on successfull converstion it will credit ?sr= parameter as source. If left null, credit will be given to url, the user came from.
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Copyright (c) 2011 [name of plugin creator], released under the MIT license
|
21
|
+
Webonise Software Solutions.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#require 'rake'
|
2
|
+
#require 'rake/testtask'
|
3
|
+
#require 'rake/rdoctask'
|
4
|
+
#
|
5
|
+
#desc 'Default: run unit tests.'
|
6
|
+
#task :default => :test
|
7
|
+
#
|
8
|
+
#desc 'Test the referrer_tracker plugin.'
|
9
|
+
#Rake::TestTask.new(:test) do |t|
|
10
|
+
# t.libs << 'lib'
|
11
|
+
# t.libs << 'test'
|
12
|
+
# t.pattern = 'test/**/*_test.rb'
|
13
|
+
# t.verbose = true
|
14
|
+
#end
|
15
|
+
#
|
16
|
+
#desc 'Generate documentation for the referrer_tracker plugin.'
|
17
|
+
#Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
# rdoc.rdoc_dir = 'rdoc'
|
19
|
+
# rdoc.title = 'ReferrerTracker'
|
20
|
+
# rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
# rdoc.rdoc_files.include('README')
|
22
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
#end
|
24
|
+
|
25
|
+
require 'jeweler'
|
26
|
+
Jeweler::Tasks.new do |gem|
|
27
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
28
|
+
gem.name = "referrer_tracker"
|
29
|
+
gem.summary = %Q{Tracks the urls references.}
|
30
|
+
gem.description = %Q{It pulls in the ?ref= and ?sr= type references from urls and marks visitor comings from those urls.}
|
31
|
+
gem.email = "rtdp@weboniselab.com"
|
32
|
+
gem.authors = ["rtdp"]
|
33
|
+
gem.version = "0.0.1"
|
34
|
+
end
|
35
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/init.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Include hook code here
|
2
|
+
require File.join(File.dirname(__FILE__), "lib", "referrer_tracker")
|
3
|
+
|
4
|
+
#
|
5
|
+
#load the configutraions from yml
|
6
|
+
ReferrerTracker::Utils.load_configuration_yaml
|
7
|
+
|
8
|
+
#
|
9
|
+
# load models - ReferrerTracker model
|
10
|
+
#
|
11
|
+
path = File.join(File.dirname(__FILE__), 'lib', 'app', "models", "track.rb")
|
12
|
+
$LOAD_PATH << path
|
13
|
+
ActiveSupport::Dependencies.load_file(path)
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/db/schema.rb
ADDED
File without changes
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module ReferrerTracker::Utils
|
2
|
+
|
3
|
+
class NotConfigured < Exception; end
|
4
|
+
|
5
|
+
class << self
|
6
|
+
attr_accessor :conf
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# to give current pairs order in list of actions
|
11
|
+
def step
|
12
|
+
number = ReferrerTracker::Utils.conf[current_track]["actions"].split.find_index(current_c_a_pair)
|
13
|
+
number.nil? ? 0 : number+1
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# to get value of current source value specified with referrer_parameter
|
18
|
+
def current_source_value
|
19
|
+
params[get_yml_attributes("referrer_parameter").to_s.to_sym]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# to get value of current source key specified with referrer_parameter
|
24
|
+
def current_source_key
|
25
|
+
get_yml_attributes("referrer_parameter").to_s.to_sym
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# checks value for conversion rate
|
30
|
+
def conversion_rate?
|
31
|
+
get_yml_attributes("conversion_rate").first
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
#
|
36
|
+
# Returns array of controller-action pairs present in .yml conf file.
|
37
|
+
def config_actions
|
38
|
+
get_yml_attributes("actions").map{|i| i.split}.flatten
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#
|
43
|
+
# get current track here
|
44
|
+
def current_track
|
45
|
+
result = ""
|
46
|
+
ReferrerTracker::Utils.conf.each_pair do |k, v|
|
47
|
+
if v["actions"].split.include?(current_c_a_pair) and !result.present?
|
48
|
+
result = k
|
49
|
+
end
|
50
|
+
end
|
51
|
+
result
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
#
|
56
|
+
# Gives current controller action pair
|
57
|
+
def current_c_a_pair
|
58
|
+
[params[:controller], params[:action]].join("#")
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
#
|
63
|
+
# Getter methods over module got get conf,
|
64
|
+
# raises NotConfigured, if nil
|
65
|
+
def self.conf
|
66
|
+
@conf || raise_unconfigured_exception
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
#
|
71
|
+
# NotConfigured exception rising class
|
72
|
+
def self.raise_unconfigured_exception
|
73
|
+
raise NotConfigured.new("No configuration provided for Referrer Tracker.")
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
#
|
78
|
+
# Loads configuration from yml file. called at application start.
|
79
|
+
#
|
80
|
+
def self.load_configuration_yaml
|
81
|
+
config = YAML.load(File.read(File.join(Rails.root,"config","referrer_tracker.yml")))
|
82
|
+
raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from referrer_tracker.yml. Is it set up?") if config.nil?
|
83
|
+
self.conf = config#.with_indifferent_access
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
#
|
88
|
+
# Give Attributes from yml file
|
89
|
+
def get_yml_attributes(action)
|
90
|
+
ReferrerTracker::Utils.conf.values.map{|i| i["#{action}"]}
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
#
|
95
|
+
# This is to check if current referrer key is the one defined in configs.
|
96
|
+
#
|
97
|
+
#
|
98
|
+
def source_match?
|
99
|
+
params[current_source_key.to_sym].present?
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
class ActionController::Base
|
3
|
+
before_filter :notice_referrer
|
4
|
+
end
|
5
|
+
|
6
|
+
module ReferrerTracker
|
7
|
+
include Utils
|
8
|
+
|
9
|
+
def notice_referrer
|
10
|
+
if config_actions.include?(current_c_a_pair)
|
11
|
+
create_track_value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def create_track_value
|
17
|
+
if step==1
|
18
|
+
create_for_step(1, current_source_value) if conversion_rate? && source_match?
|
19
|
+
session[current_source_key] = current_source_value
|
20
|
+
end
|
21
|
+
if step!=1
|
22
|
+
create_for_step(2, session[current_source_key])
|
23
|
+
session[current_source_key] = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def create_for_step(step, source)
|
29
|
+
ReferrerTrack.create(:step => step,
|
30
|
+
:track => current_track,
|
31
|
+
:source => source )
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
namespace :db do
|
2
|
+
namespace :migrate do
|
3
|
+
description = "Migrate the database through scripts in vendor/plugins/referrel_tracker/lib/db/migrate"
|
4
|
+
description << "and update db/schema.rb by invoking db:schema:dump."
|
5
|
+
description << "Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
6
|
+
|
7
|
+
desc description
|
8
|
+
task :rt_setup => :environment do
|
9
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
10
|
+
ActiveRecord::Migrator.migrate("vendor/plugins/referrer_tracker/lib/db/migrate/", ENV['VERSION'])
|
11
|
+
Rake::Task["db:migrate"].execute
|
12
|
+
Rake::Task["db:schema:dump"].invoke
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# namespace :rollback do
|
17
|
+
# description = "Migrate the database through scripts in vendor/plugins/referrel_tracker/lib/db/migrate"
|
18
|
+
# description << "and update db/schema.rb by invoking db:schema:dump."
|
19
|
+
# description << "Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
20
|
+
#
|
21
|
+
# desc description
|
22
|
+
# task :rt_rollback => :environment do
|
23
|
+
# ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
24
|
+
# ActiveRecord::Migration.migrate(Dir.glob("vendor/plugins/referrer_tracker/lib/db/migrate/*").first)
|
25
|
+
# Rake::Task["db:rollback"].execute
|
26
|
+
# Rake::Task["db:schema:dump"].invoke
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{referrer_tracker}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["rtdp"]
|
12
|
+
s.date = %q{2011-06-01}
|
13
|
+
s.description = %q{It pulls in the ?ref= and ?sr= type references from urls and marks visitor comings from those urls.}
|
14
|
+
s.email = %q{rtdp@weboniselab.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"init.rb",
|
23
|
+
"install.rb",
|
24
|
+
"lib/app/models/track.rb",
|
25
|
+
"lib/db/migrate/20110523140707_create_referrer_track_model.rb",
|
26
|
+
"lib/db/schema.rb",
|
27
|
+
"lib/referrer_tracker.rb",
|
28
|
+
"lib/referrer_tracker/utils.rb",
|
29
|
+
"lib/tasks/set_up.rake",
|
30
|
+
"referrer_tracker.gemspec",
|
31
|
+
"test/old_referrer_tracker.rb",
|
32
|
+
"test/referrer_tracker_test.rb",
|
33
|
+
"test/test_helper.rb",
|
34
|
+
"uninstall.rb"
|
35
|
+
]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Tracks the urls references.}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
else
|
46
|
+
end
|
47
|
+
else
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# ReferrerTracker
|
2
|
+
|
3
|
+
class ActionController::Base
|
4
|
+
before_filter :note_referrer
|
5
|
+
after_filter :save_referrer
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
module ReferrerTracker
|
10
|
+
class NotConfigured < Exception; end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :conf
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.conf
|
17
|
+
@conf || raise_unconfigured_exception
|
18
|
+
end
|
19
|
+
|
20
|
+
def note_referrer
|
21
|
+
logger.info("+===========+++++++++===++++++++===++++++++====+++++===+++++=+++=+++==+++=++++=+++==+++=+++==+++==++++")
|
22
|
+
logger.info(params["action"])
|
23
|
+
logger.info(controller.inspect)
|
24
|
+
logger.info(ReferrerTracker.conf.inspect)
|
25
|
+
|
26
|
+
configurations = ReferrerTracker.conf
|
27
|
+
controller_action = [params[:controller], params[:action]].join("#")
|
28
|
+
conf_actions = get_yml_attributes("start_action")
|
29
|
+
logger.info(controller_action)
|
30
|
+
|
31
|
+
|
32
|
+
if conf_actions.include?(controller_action)
|
33
|
+
logger.info("=====+++++++++++=====++++++=====+++++++=")
|
34
|
+
logger.info("inside if of note_referrer")
|
35
|
+
|
36
|
+
current_configuration = configurations["#{get_current_config_key(controller_action)}"]
|
37
|
+
logger.info(current_configuration.inspect)
|
38
|
+
source = current_configuration["referral_parameter"]
|
39
|
+
logger.info(current_configuration["referral_parameter"])
|
40
|
+
session[source.to_sym] = params[source.to_sym] if params[source.to_sym].present?
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def save_referrer
|
46
|
+
logger.info(session[:sr])
|
47
|
+
logger.info("@tracker_resource.inspect")
|
48
|
+
logger.info(@tracker_resource.inspect)
|
49
|
+
if session[:sr].present?
|
50
|
+
logger.info("saving referrer as "+ session[:sr])
|
51
|
+
Track.create(:source => session[:sr], :resource_id => user.id, :resource_type => user.class.to_s)
|
52
|
+
session[:sr] = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.raise_unconfigured_exception
|
58
|
+
raise NotConfigured.new("No configuration provided for Referrer Tracker.")
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.load_facebooker_yaml
|
62
|
+
config = YAML.load(File.read(File.join(Rails.root,"config","referrer_tracker.yml")))
|
63
|
+
raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from referrer_tracker.yml. Is it set up?") if config.nil?
|
64
|
+
self.conf = config#.with_indifferent_access
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_yml_attributes(action)
|
68
|
+
ReferrerTracker.conf.values.map{|i| i["#{action}"]}
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_current_config_key(controller_action)
|
72
|
+
result = ""
|
73
|
+
ReferrerTracker.conf.each_pair do |k, v|
|
74
|
+
if v.has_value?(controller_action) and !result.present?
|
75
|
+
result = k
|
76
|
+
end
|
77
|
+
end
|
78
|
+
result
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
#Load the model files.
|
84
|
+
path = File.join(File.dirname(__FILE__), 'app', "models", "track.rb")
|
85
|
+
$LOAD_PATH << path
|
86
|
+
ActiveSupport::Dependencies.load_file(path)
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: referrer_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- rtdp
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-01 00:00:00 +05:30
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: It pulls in the ?ref= and ?sr= type references from urls and marks visitor comings from those urls.
|
23
|
+
email: rtdp@weboniselab.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
files:
|
31
|
+
- MIT-LICENSE
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- init.rb
|
35
|
+
- install.rb
|
36
|
+
- lib/app/models/track.rb
|
37
|
+
- lib/db/migrate/20110523140707_create_referrer_track_model.rb
|
38
|
+
- lib/db/schema.rb
|
39
|
+
- lib/referrer_tracker.rb
|
40
|
+
- lib/referrer_tracker/utils.rb
|
41
|
+
- lib/tasks/set_up.rake
|
42
|
+
- referrer_tracker.gemspec
|
43
|
+
- test/old_referrer_tracker.rb
|
44
|
+
- test/referrer_tracker_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
- uninstall.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage:
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirements: []
|
75
|
+
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 1.3.7
|
78
|
+
signing_key:
|
79
|
+
specification_version: 3
|
80
|
+
summary: Tracks the urls references.
|
81
|
+
test_files: []
|
82
|
+
|