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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481bcd3da9754aa9e8e3741a62f08201c89f876c
4
- data.tar.gz: 4000e1c620372393ebc2faf8fdfe8f3cfee49109
3
+ metadata.gz: c6bed06a6226dae6e1b9989ec7eb1fce1fb1b8ab
4
+ data.tar.gz: 6e58e958c011401c0053b43b8ca027b90cce3187
5
5
  SHA512:
6
- metadata.gz: f16a73eded0bccdaf79addce8b20eae7da5d00782d5b1a61b01f2d79817ac99077f75f856b15e54698245b806833edd351c6eceab63f8166c05af9efe045f97c
7
- data.tar.gz: 3d67fa6456dc53472edabea688b39f3df523b9c88f9e89c925b60a40a3902a5ad2c68fb8e847ec32cb542133ad77754d428233035b617e131b4dcb94b4bfa984
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
- not yet production ready
18
+ staging...
19
19
 
20
20
  == Install
21
21
 
22
- at this stage only by github:
23
- so add to your Gemfile
22
+ Add to your Gemfile
24
23
 
25
- gem 'acts_as_referred', :git => 'git://github.com/erpe/acts_as_referred.git'
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
- if self.request_query.match(/utm_campaign/) || self.request_query.match(/utm_term/)
74
- return process_google_tagged(self.request_query)
75
- end
76
- if self.request_query.match(/pk_campaign/) || self.request_query.match(/pk_kwd/)
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 process_google_tagged(string)
88
- hash = Hash[* string.split('&').collect { |i| i.split('=') }.flatten]
89
+ def process_tagged
90
+ hash = Hash[*(self.request_query.split('&').collect { |i| i.split('=') }.flatten)]
89
91
  retval = nil
90
- hash.keys.each do |key|
91
- case key
92
- #when 'utm_source'
93
- # source = hash[key]
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
- retval
105
- end
106
-
107
- # standard piwik campaign-tracking
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsReferred
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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&pk_term=dynamite', prepare_booking(piwik_params).referee.request_query
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&pk_term=dynamite"
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&pk_term=dynamite"
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
  SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20131002113238"]]
2691
2691
   (172.0ms) commit transaction
2692
2692
  ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
2693
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2694
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2695
+ Referee Load (0.3ms) SELECT "referees".* FROM "referees" ORDER BY "referees"."id" ASC LIMIT 1