traffic_mansion 0.0.3 → 0.0.4

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: 266a7af2b5126a19ec321038591503a5ad4a54d0
4
- data.tar.gz: afb4ca3a84ddae2cab9168cc3886c69263b0b470
3
+ metadata.gz: a717cc1264a412fe5239c68178c5cc461b56c86e
4
+ data.tar.gz: 766f0dd67e6906441f7d3db4d7dd1c78e2805fc5
5
5
  SHA512:
6
- metadata.gz: a5fab358fe75bf7e6d8b1920d1a16be2cb1a8b0bbae50f3d13c60d40dd1168732e651ce38372702a77eb6b8a6c42eb4fdc027bec2824a09d3dee50899162321f
7
- data.tar.gz: 03574396649425bf1c1dddd3864139971c9fabeb3250f03ba50ccdaa5a39a9cea3a31dfeea6c81e16b553466357a9970cd6e09af268d6630ac94311000cb41a9
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
- :campaign_id => @campaign_id,
23
- :keyword => nil,
24
- :timestamp => Time.now.to_i,
25
- :http_host => @http_host,
26
- :remote_addr => @remote_addr,
27
- :http_referer => nil,
28
- :visit_id => @visit_id,
29
- :affiliate_id => @affiliate_id
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
- :visit_id => @visit_id,
57
- :active => is_create ? 0 : 1,
58
- :timestamp => Time.now.to_i,
59
- :remote_addr => @remote_addr,
60
- :user_id => @user_id
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
- :visit_id => @visit_id,
69
- :timestamp => Time.now.to_i,
70
- :amount => nil,
71
- :product_code => nil,
72
- :user_id => @user_id,
73
- :username => @username,
74
- :transaction => nil,
75
- :remote_addr => @remote_addr,
76
- :command => command
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
@@ -1,3 +1,3 @@
1
1
  module TrafficMansion
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  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.3
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-20 00:00:00.000000000 Z
11
+ date: 2013-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler