universal-track-manager 0.7.0.alpha → 0.7.5.alpha2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d480176796bb905c66f3e4eb2904402232548966be5183768033636b9e50d7b
4
- data.tar.gz: 0a7762ea705d448444a4113e254c49ba9e77588a4880197c5244e46388266637
3
+ metadata.gz: 06de91d3860d6f3e8000f622b2ab6209e723f492bce5548891569586e2855c6a
4
+ data.tar.gz: efb6b01f09df116b2d7b66273f276c907f2da61c3a1a41b9de29886e69b16611
5
5
  SHA512:
6
- metadata.gz: 99679f236136ab3eed671f2a0319cd01e53ca833589b97fab3e289eaa1fb5647bce188e0d4fbce05c9b5ef9ed0e09f65669e84ac2920c5430fbb1b89f03e0083
7
- data.tar.gz: 6997c26bf61ecbcb8e4867a3dfac99158d4b885209248746c364178acd3405698a8e210204d0a619f34c6a0c8fb8ef4badd4f24bb105292a9d5c9dbef47e1bc0
6
+ metadata.gz: 8ce9e03d5f717be02df2515a91c9e708f6228befbce12d30df9ac6761a8a6d162ac602d17451d28a9100d2f82a32defae3e46ce2881e9d22c6eaa9540328ae25
7
+ data.tar.gz: 54fb059bf6f826609f4b3c19af8d8be265a13271b1898be044c563f0ce159925f04e0862ff508cbff0303dd1110f9e2cddf3c94dd4ad32d2558be17e51647df1
@@ -4,7 +4,8 @@ class CreateUniversalTrackManagerTables < ActiveRecord::Migration<%= migration_v
4
4
 
5
5
  create_table :browsers do |t|
6
6
  # this table gets automatically populated by inbound traffic
7
- t.string :name, size: 255
7
+ t.string :name, limit: 255
8
+ t.timestamps
8
9
  end
9
10
 
10
11
  add_index :browsers, :name
@@ -12,10 +13,11 @@ class CreateUniversalTrackManagerTables < ActiveRecord::Migration<%= migration_v
12
13
  create_table :campaigns do |t|
13
14
  # this table gets automatically populated by inbound traffic
14
15
  #GENERATOR INSERTS CAMPAIGN COLUMNS HERE
16
+ t.string :sha1, limit: 40
15
17
  t.timestamps
16
18
  end
17
19
 
18
- #GENERATOR INSERTS CAMPAIGN INDEX HERE
20
+ add_index :campaigns, :sha1
19
21
 
20
22
  create_table :visits do |t|
21
23
  t.datetime :first_pageload
@@ -23,10 +25,12 @@ class CreateUniversalTrackManagerTables < ActiveRecord::Migration<%= migration_v
23
25
  t.integer :original_visit_id
24
26
  t.integer :campaign_id
25
27
  t.integer :browser_id
26
- t.string :ip_v4_address, length: 15
28
+ t.string :ip_v4_address, limit: 15
27
29
 
28
30
  t.integer :viewport_width
29
31
  t.integer :viewport_height
32
+ t.integer :count, default: 1
33
+ t.timestamps
30
34
  end
31
35
  end
32
36
  end
@@ -1,8 +1,6 @@
1
1
 
2
2
  require 'rails/generators'
3
3
 
4
- require 'byebug'
5
-
6
4
  module UniversalTrackManager
7
5
  class InstallGenerator < Rails::Generators::Base
8
6
  include Rails::Generators::Migration
@@ -12,7 +10,13 @@ module UniversalTrackManager
12
10
  source_root File.expand_path('../templates', __dir__)
13
11
 
14
12
  class_option :orm, type: 'boolean'
15
- class_option :param_list, type: :string, default: 'utm_source,utm_medium,utm_campaign,utm_content,utm_term'
13
+
14
+ class_option :param_list, type: :string, default: nil # DEPRECATED --- DO NOT USE
15
+
16
+
17
+
18
+ class_option :add, type: :string, default: nil
19
+ class_option :only, type: :string, default: nil
16
20
 
17
21
 
18
22
  def self.next_migration_number(path)
@@ -21,19 +25,45 @@ module UniversalTrackManager
21
25
 
22
26
  desc "Creates an initializer for Universal Track Manager and copy files to your application."
23
27
  def create_universal_track_manager_migration
24
- @params = options['param_list']
28
+ # guard against pre-0.7.3 sytnax
29
+ if options['param_list']
30
+ puts "Oops (FATAL): param_list is removed; use 'add' to augment the default list of fields or use 'only' to replace it"
31
+ exit
32
+ end
33
+
34
+ # guard against using both 'add' and 'only'
35
+ if options['add'] && options['only']
36
+ puts "Oops (FATAL): You specified both 'add' and 'only'; use 'add' to augment the default list of fields OR use 'only' to replace it"
37
+ exit
38
+ end
39
+
40
+ @default_params = %w{utm_source utm_medium utm_campaign utm_content utm_term}
41
+
42
+ if options['add']
43
+ options['add'].split(",").each do |p|
44
+ if !@default_params.include?(p)
45
+ @default_params << p
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+ if options['only']
52
+ @default_params = []
53
+ options['only'].split(",").each do |p|
54
+ @default_params << p
55
+ end
56
+ end
57
+
25
58
  column_defs = ""
26
- @params.split(',').each do |p|
59
+ @default_params.each do |p|
27
60
  column_defs += " t.string :#{p}, limit:256\n"
28
61
  end
29
-
30
- index_def = "add_index :campaigns, #{@params.split(',').map{|c| c.to_sym}.to_s}, name: 'utm_all_combined'"
31
62
  copy_file "create_universal_track_manager_tables.rb", "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged"
32
- byebug
33
63
  gsub_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged", "#GENERATOR INSERTS CAMPAIGN COLUMNS HERE", column_defs
34
- byebug
35
- gsub_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged", "#GENERATOR INSERTS CAMPAIGN INDEX HERE", index_def
36
64
  migration_template "create_universal_track_manager_tables.rb-staged", "db/migrate/create_universal_track_manager_tables.rb"
65
+
66
+ remove_file "#{self.class.source_root}/create_universal_track_manager_tables.rb-staged"
37
67
  end
38
68
 
39
69
  def create_universal_track_manager_initializer
@@ -41,6 +71,7 @@ module UniversalTrackManager
41
71
  copy_file "universal_track_manager.rb", "#{self.class.source_root}/universal_track_manager.rb-staged"
42
72
  gsub_file "#{self.class.source_root}/universal_track_manager.rb-staged", "#GENERATOR INSERTS CAMPAIGN COLUMN CONFIG HERE", column_config
43
73
  copy_file 'universal_track_manager.rb-staged', 'config/initializers/universal_track_manager.rb'
74
+ remove_file "#{self.class.source_root}/universal_track_manager.rb-staged"
44
75
  end
45
76
 
46
77
  def migration_version
@@ -27,7 +27,7 @@ module UniversalTrackManagerConcern
27
27
 
28
28
  def user_agent
29
29
  return nil if ! UniversalTrackManager.track_user_agent?
30
- request.user_agent[0..255]
30
+ request.user_agent[0..254]
31
31
  end
32
32
 
33
33
  def now
@@ -83,9 +83,16 @@ module UniversalTrackManagerConcern
83
83
 
84
84
  def find_or_create_campaign_by_current
85
85
  return nil if ! UniversalTrackManager.track_utms?
86
- campaign = UniversalTrackManager::Campaign.find_or_create_by(
87
- *permitted_utm_params
88
- )
86
+ gen_sha1 = gen_campaign_key(permitted_utm_params)
87
+
88
+ # find_or_create_by finding only by sha1 would be nice here, but how to do so with a dynamic set of columns?
89
+ # we've got a small chance of dups here due to the non-atomic find/create and sha1, but that's ok for this application.
90
+ c = UniversalTrackManager::Campaign.find_by(sha1: gen_sha1)
91
+ c ||= UniversalTrackManager::Campaign.create(*(permitted_utm_params.merge({"sha1": gen_sha1})))
92
+ end
93
+
94
+ def gen_campaign_key(params)
95
+ Digest::SHA1.hexdigest(params.keys.map{|k| k.downcase()}.sort.map{|k| {"#{k}": params[k]}}.to_s)
89
96
  end
90
97
 
91
98
  def evict_visit!(old_visit)
@@ -94,12 +101,16 @@ module UniversalTrackManagerConcern
94
101
  first_pageload: now,
95
102
  last_pageload: now,
96
103
  original_visit_id: old_visit.original_visit_id.nil? ? old_visit.id : old_visit.original_visit_id,
104
+ count: old_visit.original_visit_id.nil? ? old_visit.count + 1 : 1,
97
105
  ip_v4_address: ip_address,
98
106
  campaign: find_or_create_campaign_by_current
99
107
  }
100
108
 
101
109
  # fail silently if there is no user agent
102
- params[:browser] = find_or_create_browser_by_current if request.user_agent
110
+ if request.user_agent
111
+ params[:browser] = find_or_create_browser_by_current
112
+ end
113
+
103
114
  visit = UniversalTrackManager::Visit.create!(params)
104
115
 
105
116
  session[:visit_id] = visit.id
@@ -4,6 +4,7 @@ class UniversalTrackManager::Visit < ActiveRecord::Base
4
4
  belongs_to :campaign, class_name: "UniversalTrackManager::Campaign"
5
5
  belongs_to :browser, class_name: "UniversalTrackManager::Browser"
6
6
 
7
+ belongs_to :original_visit, optional: true
7
8
 
8
9
  def matches_all_utms?(params)
9
10
  if !campaign
@@ -16,7 +17,7 @@ class UniversalTrackManager::Visit < ActiveRecord::Base
16
17
 
17
18
  # note params are allowed to be missing
18
19
  UniversalTrackManager.campaign_column_symbols.each do |c|
19
- if campaign[c] != params[c]
20
+ if (campaign[c] && (campaign[c] != params[c])) || (!campaign[c] && params[c])
20
21
  return false
21
22
  end
22
23
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module UniversalTrackManager
2
- VERSION = "0.7.0.alpha"
2
+ VERSION = "0.7.5.alpha2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universal-track-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.alpha
4
+ version: 0.7.5.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-29 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +68,7 @@ dependencies:
68
68
  version: '2.2'
69
69
  description: Simple, plug & play visitor tracking by user agent (browser), IP address,
70
70
  referrer, and UTM parameters.
71
- email: jason.fb@datatravels.com
71
+ email: tech@datatravels.com
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
@@ -84,13 +84,12 @@ files:
84
84
  - lib/universal_track_manager/models/campaign.rb
85
85
  - lib/universal_track_manager/models/visit.rb
86
86
  - lib/version.rb
87
- homepage: https://blog.jasonfleetwoodboldt.com/my-open-source-projects/universal-track-manager/
87
+ homepage: https://jasonfleetwoodboldt.com/my-open-source-projects/universal-track-manager/
88
88
  licenses:
89
89
  - MIT
90
90
  metadata:
91
91
  source_code_uri: https://github.com/jasonfb/universal_track_manager
92
- documentation_uri: https://jfb.teachable.com/p/gems-by-jason
93
- homepage_uri: https://blog.jasonfleetwoodboldt.com/my-open-source-projects/universal-track-manager/
92
+ homepage_uri: https://github.com/jasonfb/universal_track_manager
94
93
  post_install_message: |
95
94
  ---------------------------------------------
96
95
  Welcome to Universal Track Manager
@@ -112,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
111
  - !ruby/object:Gem::Version
113
112
  version: 1.3.1
114
113
  requirements: []
115
- rubygems_version: 3.2.7
114
+ rubygems_version: 3.1.6
116
115
  signing_key:
117
116
  specification_version: 4
118
- summary: A gem to track visitors to your website.
117
+ summary: A gem to track visitors and their UTMs to your website.
119
118
  test_files: []