utm_tracker 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +40 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/utm_tracker/helper.rb +11 -0
- data/lib/utm_tracker/matcher.rb +42 -0
- data/lib/utm_tracker/version.rb +5 -0
- data/lib/utm_tracker.rb +31 -0
- data/utm_tracker.gemspec +29 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1fea7a1eba819ae12c4579d1eebe042db4a33456f1019871e335ad5f2d03b67d
|
4
|
+
data.tar.gz: 20e46a89566567ba6472f2fcd3cdb1b1a1f0bc5f0142641448d7d03b272ee6e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49aa829ce2aa8e450d8bcab536ff3af2e1ca9a0f9702f885ebe2e5db2c39c446d0896a177c61944ce7558f928ce233087d98a5617e19d743f4d5b4bddb56c70d
|
7
|
+
data.tar.gz: 6fa3c66ab5566faa13cf9fda8fb38c150357cdd2773809c84add4902502ffb3f668afae7017e496f281116e3c3081162ae92a765587d41860711db9de7e698a1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
utm_tracker (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.3)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
method_source (1.0.0)
|
12
|
+
pry (0.13.1)
|
13
|
+
coderay (~> 1.1)
|
14
|
+
method_source (~> 1.0)
|
15
|
+
rake (12.3.3)
|
16
|
+
rspec (3.10.0)
|
17
|
+
rspec-core (~> 3.10.0)
|
18
|
+
rspec-expectations (~> 3.10.0)
|
19
|
+
rspec-mocks (~> 3.10.0)
|
20
|
+
rspec-core (3.10.0)
|
21
|
+
rspec-support (~> 3.10.0)
|
22
|
+
rspec-expectations (3.10.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-mocks (3.10.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.10.0)
|
28
|
+
rspec-support (3.10.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
pry (~> 0.13)
|
35
|
+
rake (~> 12.0)
|
36
|
+
rspec (~> 3.0)
|
37
|
+
utm_tracker!
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# UtmTracker
|
2
|
+
|
3
|
+
This gem allow to save UTM tags into your Rails app. UtmTracker allows you to save in the user object with which advertisement he was registered.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- Ruby 2.7.1
|
8
|
+
- Rails 6.1.x
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'utm_tracker'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
## Usage for Rails
|
23
|
+
|
24
|
+
1. You need to generate Rails migration and add utm_data into your User model for UTM-tags:
|
25
|
+
|
26
|
+
$ rails g migration add_utm_data_to_executors utm_data:jsonb
|
27
|
+
|
28
|
+
and add not null and default modificators into rails migrations:
|
29
|
+
```ruby
|
30
|
+
def change
|
31
|
+
add_column :users, :utm_data, :jsonb, null: false, default: {}
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
and then:
|
36
|
+
|
37
|
+
$ rails db:migrate
|
38
|
+
|
39
|
+
2. Prepare link into user registration controller:
|
40
|
+
|
41
|
+
$ https://example.com?utm[source]=google&utm[medium]=cpc&utm[campaign]=testcampaign&utm[content]={adgroupid}&utm[term]={keyword}
|
42
|
+
|
43
|
+
3. Add into ApplicationController next helper for save utm_tags into current_user session:
|
44
|
+
```ruby
|
45
|
+
class ApplicationController < ActionController::Base
|
46
|
+
include UtmTracker::Helper
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
4. After that, you can use callback into your controllers for get utm data in current user session:
|
51
|
+
```ruby
|
52
|
+
before_action :get_utm_data
|
53
|
+
```
|
54
|
+
|
55
|
+
Add this callback where you plan to receive advertising traffic.
|
56
|
+
|
57
|
+
5. Into user registration controller add UtmTracker client after save user and put user object and session[:utm]:
|
58
|
+
```ruby
|
59
|
+
@utm = UtmTracker::Client.new(object: @user, utm: session[:utm])
|
60
|
+
@utm.call
|
61
|
+
```
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
66
|
+
|
67
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexlev1/utm_tracker.
|
72
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "utm_tracker"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UtmTracker
|
4
|
+
class Matcher
|
5
|
+
attr_accessor :utm_data, :utm
|
6
|
+
|
7
|
+
def initialize(utm_data, utm = {})
|
8
|
+
@utm_data = utm_data
|
9
|
+
@utm = utm
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
utm_source
|
14
|
+
utm_content
|
15
|
+
utm_medium
|
16
|
+
utm_campaign
|
17
|
+
utm_term
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def utm_source
|
23
|
+
utm[:utm_source] = utm_data['source'] if utm_data['source']
|
24
|
+
end
|
25
|
+
|
26
|
+
def utm_content
|
27
|
+
utm[:utm_content] = utm_data['content'] if utm_data['content']
|
28
|
+
end
|
29
|
+
|
30
|
+
def utm_medium
|
31
|
+
utm[:utm_medium] = utm_data['medium'] if utm_data['medium']
|
32
|
+
end
|
33
|
+
|
34
|
+
def utm_campaign
|
35
|
+
utm[:utm_campaign] = utm_data['campaign'] if utm_data['campaign']
|
36
|
+
end
|
37
|
+
|
38
|
+
def utm_term
|
39
|
+
utm[:utm_term] = utm_data['term'] if utm_data['term']
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/utm_tracker.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "utm_tracker/version"
|
4
|
+
require_relative "utm_tracker/helper"
|
5
|
+
require_relative "utm_tracker/matcher"
|
6
|
+
|
7
|
+
module UtmTracker
|
8
|
+
class Client
|
9
|
+
attr_accessor :object, :utm_matcher
|
10
|
+
|
11
|
+
def initialize(object, utm_data)
|
12
|
+
@object = object
|
13
|
+
@utm_matcher = UtmTracker::Matcher.new(utm_data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
match_utm_tags
|
18
|
+
save_utm_tags_into_database!
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def match_utm_tags
|
24
|
+
@utm_matcher.call
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_utm_tags_into_database!
|
28
|
+
object.update!(utm_data: @utm_matcher.utm)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/utm_tracker.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/utm_tracker/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "utm_tracker"
|
5
|
+
spec.version = UtmTracker::VERSION
|
6
|
+
spec.authors = ["Alexander Levashov"]
|
7
|
+
spec.email = ["alevash1@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = 'Gem for UTM tags tracking'
|
10
|
+
spec.description = %q{Allow save UTM tags into database}
|
11
|
+
spec.homepage = "https://github.com/alexlev1/utm_tracker"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.1")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/alexlev1/utm_tracker"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/alexlev1/utm_tracker"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency 'pry', '~> 0.13'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.10.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utm_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Levashov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.10.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.10.0
|
41
|
+
description: Allow save UTM tags into database
|
42
|
+
email:
|
43
|
+
- alevash1@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/utm_tracker.rb
|
57
|
+
- lib/utm_tracker/helper.rb
|
58
|
+
- lib/utm_tracker/matcher.rb
|
59
|
+
- lib/utm_tracker/version.rb
|
60
|
+
- utm_tracker.gemspec
|
61
|
+
homepage: https://github.com/alexlev1/utm_tracker
|
62
|
+
licenses: []
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/alexlev1/utm_tracker
|
65
|
+
source_code_uri: https://github.com/alexlev1/utm_tracker
|
66
|
+
changelog_uri: https://github.com/alexlev1/utm_tracker
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.7.1
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.1.4
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Gem for UTM tags tracking
|
86
|
+
test_files: []
|