gamco 0.1.0 → 0.2.0

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: 90384de6681b9f81cd09552378fcaecfcab73bff8648691845cce57b75e870f8
4
- data.tar.gz: f2fee0bfb32f91c3cbf911ce30e089af52bd0b4ae2d6b61d66c0e883f0cd2915
3
+ metadata.gz: f9d7669e0d92350bceb06b3a05a23d44138ae1ad4ab7314ce55eb0dcde41aa43
4
+ data.tar.gz: 6f35eb96d66b13d7ac550f52e206de841f60626c42aba204cd8bbd048fe2d642
5
5
  SHA512:
6
- metadata.gz: 74896f548b6938ecb6fc93ea51f34bd282c92bf6e412bc61b87ebb00de0ca43d27931466b529cd1cb3fd88f091e2946eaf3a454e77d6529eff671f21f7b087a0
7
- data.tar.gz: 977e37ecbe9dbc37b40429f0859d363e63b5c553c5597bee9340dab4c5092771c434fc655f6adfa17acabc711fac8e4cf947ebaffc23d8bb8d28cf09e0e27dff
6
+ metadata.gz: 044b24d61425016ba9306e1f98baa7727931125d6d06f4da3758e4959de3241abf8ba1c87997e0bf1b1018e91f32cafd78d30b231f528f32e1038a3740e1d1c4
7
+ data.tar.gz: f69ffbfe20862849c52ff21ea58ead2665fee86a637ed03d30177e04598a8243b23a51b35427ef571c7b4096d7cca2fd47887d5dff2af92fa3fa9ecb0a73297a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2022-09-26
3
+ ## [Released]
4
+
5
+ ## [0.2.0] - 2022-10-05
6
+
7
+ - Add Configuration.active option to control if data should
8
+ be sent to Google Analytics.
9
+
10
+ ## [0.1.1] - 2022-10-04
11
+
12
+ - Improve `ga_secure` helper to avoid using it when passed
13
+ value is nil or empty.
14
+
15
+ ## [0.1.0] - 2022-10-04
4
16
 
5
17
  - Initial release
data/README.md CHANGED
@@ -98,6 +98,22 @@ Gamco.setup do |config|
98
98
  end
99
99
  ```
100
100
 
101
+ ### Usage per environment
102
+
103
+ It is possible that you want to send data to Google Analytics just in
104
+ production environments. You can control that using the `active` configuration
105
+ option in the initializer `config/initializers/gamco.rb`:
106
+
107
+ ```ruby
108
+ Gamco.setup do |config|
109
+ # ===> Required GA4 configuration options
110
+ config.tag_id = "G-XXXXXXXXX"
111
+ config.active = Rails.application.credentials.dig(:gamco, :active)
112
+
113
+ ...
114
+ end
115
+ ```
116
+
101
117
  ## Development
102
118
 
103
119
  After checking out the repo, run `bin/setup` to install dependencies. Then,
data/gamco.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.require_paths = ["lib"]
37
37
 
38
38
  # Uncomment to register a new dependency of your gem
39
- # spec.add_dependency "example-gem", "~> 1.0"
39
+ spec.add_dependency "rails", ">= 5.0"
40
40
 
41
41
  # For more information and examples about making a new gem, check out our
42
42
  # guide at: https://bundler.io/guides/creating_gem.html
data/lib/gamco/builder.rb CHANGED
@@ -34,12 +34,10 @@ module Gamco
34
34
  end
35
35
 
36
36
  def gtag_script_content(tag_id, options)
37
- <<-FOO
38
- window.dataLayer = window.dataLayer || [];
39
- function gtag(){dataLayer.push(arguments);}
40
- gtag('js', new Date());
41
- gtag('config', '#{tag_id}', #{options.to_json});
42
- FOO
37
+ "window.dataLayer = window.dataLayer || [];"\
38
+ "function gtag(){dataLayer.push(arguments);}"\
39
+ "gtag('js', new Date());"\
40
+ "gtag('config', '#{tag_id}', #{options.to_json});"
43
41
  end
44
42
 
45
43
  def tag_manager_script_url
@@ -3,6 +3,7 @@
3
3
  module Gamco
4
4
  module Configuration
5
5
  mattr_accessor :tag_id, default: nil
6
+ mattr_accessor :active, default: false
6
7
 
7
8
  mattr_accessor :secure, default: -> (value) do
8
9
  Digest::MD5.hexdigest(value)
@@ -2,6 +2,10 @@
2
2
 
3
3
  module Gamco
4
4
  module Errors
5
- class NoTagId < StandardError; end
5
+ class NoTagId < StandardError
6
+ def initialize(message = "Configure your TAG_ID in your initializer.")
7
+ super
8
+ end
9
+ end
6
10
  end
7
11
  end
data/lib/gamco/helper.rb CHANGED
@@ -3,15 +3,18 @@
3
3
  module Gamco
4
4
  module Helper
5
5
  def ga_javascript_tags(tag_id: Configuration.tag_id, **options)
6
+ return unless Configuration.active
6
7
  raise Errors::NoTagId unless tag_id.present?
7
8
  ga_builder.javascript_tags(tag_id, options)
8
9
  end
9
10
 
10
11
  def ga_tag(type, event, options = {})
12
+ return unless Configuration.active
11
13
  ga_builder.tag(type, event, options)
12
14
  end
13
15
 
14
16
  def ga_secure(value)
17
+ return unless value.present?
15
18
  Configuration.secure.call(value)
16
19
  end
17
20
 
data/lib/gamco/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gamco
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/gamco.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "gamco/version"
4
4
  require_relative "gamco/builder"
5
5
  require_relative "gamco/helper"
6
6
  require_relative "gamco/configuration"
7
+ require_relative "gamco/errors/no_tag_id"
7
8
 
8
9
  module Gamco
9
10
  extend Configuration
@@ -3,6 +3,7 @@
3
3
  Gamco.setup do |config|
4
4
  # ===> Required GA4 configuration options
5
5
  # config.tag_id = "G-XXXXXXXXXXX"
6
+ # config.tag_id = false
6
7
 
7
8
  # ===> Method to secure sensitive data.
8
9
  # config.secure = -> (value) {
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Gutiérrez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
13
27
  description: This gem aims to provide a simple and easy way to send data to Google
14
28
  Analytics.
15
29
  email: