rack_utm 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: c6db47ee508d12b422779d894722b79fd00f86af1c3a4e9502c8d86fe6253f39
4
- data.tar.gz: a38ef5bb15145091726220b34c410fa269713507472f0f618527f1548b93289c
3
+ metadata.gz: ba7edca42f7dfe760ef7d3cbec3a2dff3470bed49ed85609ccb860c5ea909c59
4
+ data.tar.gz: e62dcaa1a79651094e1f32f33acc68cff317054883a1944393e5505be935c9d7
5
5
  SHA512:
6
- metadata.gz: be30902a47509de9aef3560aa0314f831eaf52d2ef14636e59df42a58ad2e2c9135f71cb5e15bd250680d6b9433037eea02b98dc74a916a25fe5d2596b3c81b1
7
- data.tar.gz: 75faa4cae3e135054cafa2e3da8ba0fd606133c2a9bd758a5ec52054a5abec277c26b92a49e36d5ce1e8a8f8a686e5814c88c00a8e8b8951d9f88332a910dee7
6
+ metadata.gz: ed216746f975a866b4f3f4fb2e2aa0d5cf34752d566965380839a4afefa056f859931ffcd39665bad908eb04deebcd35721ac332408b961cc70daf68e474dca6
7
+ data.tar.gz: 9c4286498c85360615b6a28a6692ab531aaa72884cd6341b3399ce6c5569d812ada48c697a6c5984290355bf990cac75e84342486f874e82a0abe8376c2c9a38
data/README.md CHANGED
@@ -1,43 +1,106 @@
1
- # RackUtm
1
+ Rack::UTM
2
+ ================
2
3
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rack_utm`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ Rack::UTM is a rack middleware that extracts information about the utm tracking codes.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ Common Scenario
7
+ ---------------
6
8
 
7
- ## Installation
9
+ UTM links tracking is very common task if you want to promote your online business. This middleware helps you to do that.
8
10
 
9
- Add this line to your application's Gemfile:
11
+ 1. Use UTM Link to promote your business like <code>http://yoursite.org?utm_source=ABC123....</code>.
12
+ 2. A user clicks through the link and lands on your site.
13
+ 3. Rack::Utm middleware finds <code>utm_*</code> parameters in the request, extracts them and saves it in a cookie
14
+ 4. User signs up (now or later) and you know the utm params the user has assigned
15
+ 5. PROFIT!
10
16
 
11
- ```ruby
12
- gem 'rack_utm'
13
- ```
17
+ Installation
18
+ ------------
14
19
 
15
- And then execute:
20
+ Piece a cake:
16
21
 
17
- $ bundle
22
+ gem install rack_utm
18
23
 
19
- Or install it yourself as:
20
24
 
21
- $ gem install rack_utm
25
+ Rails 3+ Example Usage
26
+ ---------------------
22
27
 
23
- ## Usage
28
+ Add the middleware to your application stack:
24
29
 
25
- TODO: Write usage instructions here
30
+ # Rails 3 App - in config/application.rb
31
+ class Application < Rails::Application
32
+ ...
33
+ config.middleware.use Rack::Utm
34
+ ...
35
+ end
26
36
 
27
- ## Development
37
+ # Rails 2 App - in config/environment.rb
38
+ Rails::Initializer.run do |config|
39
+ ...
40
+ config.middleware.use "Rack::Utm"
41
+ ...
42
+ end
28
43
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+ Now you can check any request to see who came to your site via an affiliated link and use this information in your application. Affiliate tag is saved in the cookie and will come into play if user returns to your site later.
30
45
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
46
+ class ExampleController < ApplicationController
47
+ def index
48
+ str = if request.env['utm_source']
49
+ "Hallo, user! You've been referred here by #{request.env['utm_source']}, #{request.env['utm_medium']}, ...."
50
+ else
51
+ "We're glad you found us on your own!"
52
+ end
32
53
 
33
- ## Contributing
54
+ render :text => str
55
+ end
56
+ end
34
57
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/ihatov08/rack_utm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
58
 
37
- ## License
59
+ Customization
60
+ -------------
38
61
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
+ By default cookie is set for 30 days, you can extend time to live with <code>:ttl</code> option (default is 30 days).
40
63
 
41
- ## Code of Conduct
64
+ #Rails 3+ in config/application.rb
65
+ class Application < Rails::Application
66
+ ...
67
+ config.middleware.use Rack::Utm, { cookie_time_to_live: 60*60*24*30 }
68
+ ...
69
+ end
42
70
 
43
- Everyone interacting in the RackUtm project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ihatov08/rack_utm/blob/master/CODE_OF_CONDUCT.md).
71
+ The <code>:domain</code> option allows to customize cookie domain.
72
+
73
+ #Rails 3+ in config/application.rb
74
+ class Application < Rails::Application
75
+ ...
76
+ config.middleware.use Rack::Utm, cookie_domain: '.example.org'
77
+ ...
78
+ end
79
+
80
+ By default required parameters are `utm_source, utm_medium, utm_campaign, utm_content, utm_term`.
81
+ The <code>:required_parameters</code> option change required parameters.
82
+
83
+ #Rails 3+ in config/application.rb
84
+ class Application < Rails::Application
85
+ ...
86
+ config.middleware.use Rack::Utm, required_parameters: %w[utm_source]
87
+ ...
88
+ end
89
+
90
+ If you want to tracking optional parameters(not required), please use <code>optional_parameters</code> option.
91
+
92
+ #Rails 3+ in config/application.rb
93
+ class Application < Rails::Application
94
+ ...
95
+ config.middleware.use Rack::Utm, optional_parameters: %w[optional_param]
96
+ ...
97
+ end
98
+
99
+ Middleware will set cookie on <code>.example.org</code> so it's accessible on <code>www.example.org</code>, <code>app.example.org</code> etc.
100
+
101
+ The <code>:overwrite</code> option allows to set whether to overwrite the existing utm tag(`required_parameters`) previously stored in cookies. By default it is set to `true`.
102
+
103
+ Credits
104
+ =======
105
+
106
+ Thanks goes to Rack::Affiliates (https://github.com/alexlevin/rack-affiliates) for the inspiration.
@@ -110,7 +110,7 @@ module Rack
110
110
  value: value,
111
111
  expires: expires,
112
112
  domain: cookie_domain,
113
- cookie_path: cookie_path
113
+ path: cookie_path
114
114
  }
115
115
 
116
116
  Rack::Utils.set_cookie_header!(headers, key, cookie)
@@ -1,3 +1,3 @@
1
1
  module RackUtm
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_utm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ihatov08
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler