gamco 0.1.1 → 0.2.0

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: a8a255610ca8bbd747457d590a459eedfb4de5ccc2ca3e3458d086de8b7016f4
4
- data.tar.gz: 404876a57f493268e1efe0aa7385f5850f18350854aa7eba6d24db9b9df994e0
3
+ metadata.gz: f9d7669e0d92350bceb06b3a05a23d44138ae1ad4ab7314ce55eb0dcde41aa43
4
+ data.tar.gz: 6f35eb96d66b13d7ac550f52e206de841f60626c42aba204cd8bbd048fe2d642
5
5
  SHA512:
6
- metadata.gz: 4e83a1ca58c31800b95a8e2b75aa6e60d141070f49bb1330435cbeec4f89ef423a9d830f9eb82ea0c7929f886b9caa0439a2d6b14e394fe10c1373d26da2e60e
7
- data.tar.gz: 0e9f8198d890908060fc63fdb0c302f0fcaf9567ab4d90e5f072ef8a2e56da369e651a7c3b8332657763f86444fb6a66428fcb1b3f69dba1e82c2d2967ca7ceb
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/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,11 +3,13 @@
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
 
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.1"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails