traffic_mansion 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/README.md +57 -1
- data/lib/traffic_mansion/tracker.rb +43 -23
- data/lib/traffic_mansion/version.rb +1 -1
- 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: a717cc1264a412fe5239c68178c5cc461b56c86e
|
4
|
+
data.tar.gz: 766f0dd67e6906441f7d3db4d7dd1c78e2805fc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278896cc86058caf655a332f5f6e9ceeeee8135d9986bbdc7daa227431991789e11287a0c17aaf81c501ad80cbd0ff59652589e141925315c467e54aff631ed1
|
7
|
+
data.tar.gz: ff1f7ce3e2f06e455790252ee4b758f3392fa726a0c0b010a23e162d439e42601956120b0f5d9dd08feb0aa41e7337bfa27fa559465c214f20a46edf16ab11f0
|
data/README.md
CHANGED
@@ -8,4 +8,60 @@ Add this line to your application's Gemfile:
|
|
8
8
|
|
9
9
|
And then execute:
|
10
10
|
|
11
|
-
$ bundle
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
## Environment
|
14
|
+
|
15
|
+
The following environment variables can be set:
|
16
|
+
|
17
|
+
````
|
18
|
+
TRAFFIC_MANSION_HTTP_HOST=mydomain.com # the domain where you track from
|
19
|
+
TRAFFIC_MANSION_ENDPOINT=http://www.trafficmansion.com # the API endpoint
|
20
|
+
TRAFFIC_MANSION_ROOT_CAMPAIGN_ID=666 # the default campaign id for the root traffic if there is one
|
21
|
+
TRAFFIC_MANSION_LOG_REQUESTS=1 # set this to debug the tracking request and response
|
22
|
+
TRAFFIC_MANSION_LOG_TO_FILE=1 # set this to debug it into a file instead of the main logger
|
23
|
+
````
|
24
|
+
|
25
|
+
## Tasks
|
26
|
+
|
27
|
+
Run `traffic_mansion:create_indexes` after the instalation to set the Queue collection indexes.
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Unique visits
|
32
|
+
|
33
|
+
Track them directly from the controller:
|
34
|
+
|
35
|
+
````ruby
|
36
|
+
def track_unique_visit
|
37
|
+
if !TrafficMansion::tracked_client?(cookies)
|
38
|
+
campaign_id = TrafficMansion::get_campaign_id params[:campaign_id]
|
39
|
+
if campaign_id
|
40
|
+
event = TrafficMansion::Queue::add_unique_visit campaign_id, request.remote_ip, request.referer
|
41
|
+
cookies[TrafficMansion::COOKIE_NAME] = { :value => event.id, :expires => 30.days.from_now, :domain => :all }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
````
|
46
|
+
|
47
|
+
### Signups
|
48
|
+
|
49
|
+
Track them directly from the controller:
|
50
|
+
|
51
|
+
````ruby
|
52
|
+
def track_signup user
|
53
|
+
if TrafficMansion::tracked_client?(cookies)
|
54
|
+
TrafficMansion::Queue::add_signup cookies[TrafficMansion::COOKIE_NAME], user.id, request.remote_ip, request.referer
|
55
|
+
end
|
56
|
+
end
|
57
|
+
````
|
58
|
+
|
59
|
+
### Sales
|
60
|
+
|
61
|
+
Track them from the post response controller:
|
62
|
+
|
63
|
+
````ruby
|
64
|
+
def track_sale user, payment
|
65
|
+
TrafficMansion::Queue::add_sale user.id, payment.id, payment.amount, payment.product.name, request.remote_ip, request.referer
|
66
|
+
end
|
67
|
+
````
|
@@ -2,9 +2,11 @@ require "rest_client"
|
|
2
2
|
|
3
3
|
module TrafficMansion
|
4
4
|
class Tracker
|
5
|
-
def initialize options = {}, endpoint = ENV["TRAFFIC_MANSION_ENDPOINT"], http_host = ENV["TRAFFIC_MANSION_HTTP_HOST"]
|
5
|
+
def initialize options = {}, endpoint = ENV["TRAFFIC_MANSION_ENDPOINT"], http_host = ENV["TRAFFIC_MANSION_HTTP_HOST"], log_requests = ENV["TRAFFIC_MANSION_LOG_REQUESTS"], log_to_file = ENV["TRAFFIC_MANSION_LOG_TO_FILE"]
|
6
6
|
@endpoint = endpoint
|
7
7
|
@http_host = http_host
|
8
|
+
@log_requests = log_requests
|
9
|
+
@log_to_file = log_to_file
|
8
10
|
set_data options
|
9
11
|
end
|
10
12
|
|
@@ -19,14 +21,14 @@ module TrafficMansion
|
|
19
21
|
def visit options = {}
|
20
22
|
url = "#{@endpoint}/xd_visit.php"
|
21
23
|
params = {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
"campaign_id" => @campaign_id,
|
25
|
+
"keyword" => nil,
|
26
|
+
"timestamp" => Time.now.to_i,
|
27
|
+
"http_host" => @http_host,
|
28
|
+
"remote_addr" => @remote_addr,
|
29
|
+
"http_referer" => nil,
|
30
|
+
"visit_id" => @visit_id,
|
31
|
+
"affiliate_id" => @affiliate_id
|
30
32
|
}.merge options
|
31
33
|
get_response url, params
|
32
34
|
end
|
@@ -53,11 +55,11 @@ module TrafficMansion
|
|
53
55
|
def auth is_create, options
|
54
56
|
url = "#{@endpoint}/xd_postsignup.php"
|
55
57
|
params = {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
"visit_id" => @visit_id,
|
59
|
+
"active" => is_create ? 0 : 1,
|
60
|
+
"timestamp" => Time.now.to_i,
|
61
|
+
"remote_addr" => @remote_addr,
|
62
|
+
"user_id" => @user_id
|
61
63
|
}.merge options
|
62
64
|
get_response url, params
|
63
65
|
end
|
@@ -65,22 +67,40 @@ module TrafficMansion
|
|
65
67
|
def payment command, options
|
66
68
|
url = "#{@endpoint}/xd_postsale.php"
|
67
69
|
params = {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
"visit_id" => @visit_id,
|
71
|
+
"timestamp" => Time.now.to_i,
|
72
|
+
"amount" => nil,
|
73
|
+
"product_code" => nil,
|
74
|
+
"user_id" => @user_id,
|
75
|
+
"username" => @username,
|
76
|
+
"transaction" => nil,
|
77
|
+
"remote_addr" => @remote_addr,
|
78
|
+
"command" => command
|
77
79
|
}.merge options
|
78
80
|
get_response url, params
|
79
81
|
end
|
80
82
|
|
81
83
|
def get_response url, params
|
84
|
+
log "Endpoint", url
|
85
|
+
log "Request", params
|
82
86
|
response = RestClient.post url, params
|
87
|
+
log "Response", response
|
83
88
|
TrafficMansion::Response.new response
|
84
89
|
end
|
90
|
+
|
91
|
+
def log name, data
|
92
|
+
if @log_requests
|
93
|
+
begin
|
94
|
+
if @log_to_file
|
95
|
+
File.open("traffic_mansion.log", "a") do |f|
|
96
|
+
f.write "[#{Time.now}] #{name}: #{data}\r\n"
|
97
|
+
end
|
98
|
+
else
|
99
|
+
Rails.logger.info "[Traffic Mansion] #{name}: #{data}"
|
100
|
+
end
|
101
|
+
rescue
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
85
105
|
end
|
86
106
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traffic_mansion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AgileWings
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|