acts_as_referred 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +4 -5
- data/lib/acts_as_referred/model.rb +21 -51
- data/lib/acts_as_referred/version.rb +1 -1
- data/test/acts_as_referred_test.rb +3 -3
- data/test/dummy/log/development.log +3 -0
- data/test/dummy/log/test.log +1286 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6bed06a6226dae6e1b9989ec7eb1fce1fb1b8ab
|
4
|
+
data.tar.gz: 6e58e958c011401c0053b43b8ca027b90cce3187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5a13e45ca49b89810f65f546ca848a22979e4025dfe1cd29358c81d3cb12b60c0072f56fd5f32940ddd774b34a04d5f683b5db904269d62db9bdb1f42a5990b
|
7
|
+
data.tar.gz: 6a5e5ce3d6284cc0d5a10c78fc3f22a6d917473b003c765c0d88c5dc35ef4ac8bb2d9515bf438cce56fb3b2e70af30e0362dda7bc18f2872d47d3db2f549cfa7
|
data/README.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
{<img src="https://badge.fury.io/rb/acts_as_referred.png" alt="Gem Version" />}[http://badge.fury.io/rb/acts_as_referred]
|
2
|
+
{<img src="https://badge.fury.io/rb/acts_as_referred.png" alt="Gem Version" />}[http://badge.fury.io/rb/acts_as_referred] {<img src="https://travis-ci.org/erpe/acts_as_referred.png" />}[https://travis-ci.org/erpe/acts_as_referred] {<img src="https://codeclimate.com/repos/524d89e2f3ea00328a0fbb91/badges/b4046748a27bfa99b07b/gpa.png" />}[https://codeclimate.com/repos/524d89e2f3ea00328a0fbb91/feed]
|
3
3
|
|
4
4
|
= ActsAsReferred
|
5
5
|
|
@@ -15,14 +15,13 @@ The action then makes this data available to your model. When supplied with +act
|
|
15
15
|
|
16
16
|
== Status
|
17
17
|
|
18
|
-
|
18
|
+
staging...
|
19
19
|
|
20
20
|
== Install
|
21
21
|
|
22
|
-
|
23
|
-
so add to your Gemfile
|
22
|
+
Add to your Gemfile
|
24
23
|
|
25
|
-
gem 'acts_as_referred'
|
24
|
+
gem 'acts_as_referred'
|
26
25
|
|
27
26
|
afterwards run the rake task to create necessary database table
|
28
27
|
|
@@ -26,6 +26,12 @@ module ActsAsReferred
|
|
26
26
|
# campaign-based request
|
27
27
|
scope :campaigns, -> { where('is_campaign=?', true) }
|
28
28
|
|
29
|
+
# tags as used by google or piwik in campaign-tracking
|
30
|
+
TAGS = {
|
31
|
+
campaign: %w{ pk_campaign utm_campaign gclid },
|
32
|
+
keyword: %w{ pk_kwd utm_term}
|
33
|
+
}
|
34
|
+
|
29
35
|
# returns referrer as instance of URI
|
30
36
|
def origin_uri
|
31
37
|
has_referrer? ? URI.parse(origin) : nil
|
@@ -70,70 +76,34 @@ module ActsAsReferred
|
|
70
76
|
|
71
77
|
def process_request
|
72
78
|
if self.request_query
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
return process_piwik_tagged(self.request_query)
|
78
|
-
end
|
79
|
-
if self.request_query.match(/gclid/)
|
80
|
-
return process_google_auto_tagged(self.request_query)
|
79
|
+
TAGS.values.flatten.each do |word|
|
80
|
+
if self.request_query.match(word)
|
81
|
+
return process_tagged
|
82
|
+
end
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
|
87
|
+
|
86
88
|
# a.t.m. only care about campaign name and keywords
|
87
|
-
def
|
88
|
-
hash = Hash[*
|
89
|
+
def process_tagged
|
90
|
+
hash = Hash[*(self.request_query.split('&').collect { |i| i.split('=') }.flatten)]
|
89
91
|
retval = nil
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
when 'utm_campaign'
|
95
|
-
self.campaign = hash[key]
|
96
|
-
retval = true
|
97
|
-
#when 'utm_medium'
|
98
|
-
# medium = hash[key]
|
99
|
-
when 'utm_term'
|
100
|
-
self.keywords = hash[key]
|
92
|
+
|
93
|
+
TAGS[:campaign].each do |t|
|
94
|
+
if hash[t]
|
95
|
+
self.campaign = hash[t] if self.campaign.nil? || self.campaign.empty?
|
101
96
|
retval = true
|
102
97
|
end
|
103
98
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
def process_piwik_tagged(string)
|
109
|
-
hash = Hash[*(string.split('&').collect { |i| i.split('=') }.flatten)]
|
110
|
-
retval = nil
|
111
|
-
hash.keys.each do |key|
|
112
|
-
case key
|
113
|
-
when 'pk_campaign'
|
114
|
-
self.campaign = hash[key]
|
115
|
-
retval = true
|
116
|
-
when 'pk_kwd'
|
117
|
-
self.keywords = hash[key]
|
118
|
-
retval = true
|
99
|
+
TAGS[:keyword].each do |k|
|
100
|
+
if hash[k]
|
101
|
+
self.keywords = hash[k] if self.keywords.nil? || self.keywords.empty?
|
102
|
+
retval = true
|
119
103
|
end
|
120
104
|
end
|
121
105
|
retval
|
122
106
|
end
|
123
|
-
|
124
|
-
# adwords set to autotagging
|
125
|
-
# no chance to get campaign info by url
|
126
|
-
# would have to do cookie parsing - what would suck
|
127
|
-
def process_google_auto_tagged(string)
|
128
|
-
hash = Hash[* string.split('|').collect { |i| i.split('=') }.flatten]
|
129
|
-
retval = nil
|
130
|
-
if hash['gclid']
|
131
|
-
self.campaign = "Adwords - autotagged: #{hash['gclid']}"
|
132
|
-
self.is_campaign = true
|
133
|
-
retval = true
|
134
|
-
end
|
135
|
-
retval
|
136
|
-
end
|
137
107
|
|
138
108
|
def process_origin
|
139
109
|
self.origin_host = URI.parse(origin).host
|
@@ -34,7 +34,7 @@ class ActsAsReferredTest < ActiveSupport::TestCase
|
|
34
34
|
end
|
35
35
|
|
36
36
|
test 'test_a_booking_query' do
|
37
|
-
assert_equal 'pk_campaign=Explosives&
|
37
|
+
assert_equal 'pk_campaign=Explosives&pk_kwd=dynamite', prepare_booking(piwik_params).referee.request_query
|
38
38
|
end
|
39
39
|
|
40
40
|
test 'test_a_order_with_no_referrer_should_return_nil' do
|
@@ -60,7 +60,7 @@ class ActsAsReferredTest < ActiveSupport::TestCase
|
|
60
60
|
|
61
61
|
def no_referer_params
|
62
62
|
{
|
63
|
-
request: "http://domain.com/foo?pk_campaign=Explosives&
|
63
|
+
request: "http://domain.com/foo?pk_campaign=Explosives&pk_kwd=dynamite"
|
64
64
|
}
|
65
65
|
|
66
66
|
end
|
@@ -75,7 +75,7 @@ class ActsAsReferredTest < ActiveSupport::TestCase
|
|
75
75
|
def piwik_params
|
76
76
|
{
|
77
77
|
referrer: 'http://www.nsa.gov/about/values/index.shtml?attr=terror&reason=politics',
|
78
|
-
request: "http://domain.com/foo?pk_campaign=Explosives&
|
78
|
+
request: "http://domain.com/foo?pk_campaign=Explosives&pk_kwd=dynamite"
|
79
79
|
}
|
80
80
|
end
|
81
81
|
|
@@ -2690,3 +2690,6 @@ Migrating to CreateReferee (20131002113238)
|
|
2690
2690
|
[1m[36mSQL (0.3ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20131002113238"]]
|
2691
2691
|
[1m[35m (172.0ms)[0m commit transaction
|
2692
2692
|
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
2693
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
2694
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
2695
|
+
[1m[36mReferee Load (0.3ms)[0m [1mSELECT "referees".* FROM "referees" ORDER BY "referees"."id" ASC LIMIT 1[0m
|