Class: Consently::Providers::Base
- Inherits:
-
Object
- Object
- Consently::Providers::Base
- Defined in:
- lib/consently/providers/base.rb
Overview
A tag vendor: what scripts it needs and which consent category it falls under. Subclasses describe the snippet as data (see Consently::Script) so the view can render it live or blocked from the same description.
Direct Known Subclasses
Clarity, Custom, GoogleAds, GoogleAnalytics, GoogleTagManager, Hotjar, MetaPixel, Plausible
Constant Summary collapse
- SAFE_OPTION =
Ids are interpolated straight into JavaScript, so they are held to a shape that cannot carry a quote or a bracket out of the string.
/\A[\w\-.:\/]+\z/
Class Attribute Summary collapse
-
.default_category ⇒ Object
Set by each subclass; where a vendor is unambiguous (Plausible does not touch cookies) it can say :necessary and load right away.
-
.google ⇒ Object
writeonly
Whether this vendor is one of Google's, which is what advanced consent mode is about: those tags may load before consent because they respect the denied defaults themselves.
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .build(key, **options) ⇒ Object
-
.cookie(name, days: nil) ⇒ Object
What this vendor stores in the visitor's browser, for the policy page.
- .cookie_manifest ⇒ Object
- .google? ⇒ Boolean
- .provider_key ⇒ Object
- .provider_key=(key) ⇒ Object
- .register(key, klass) ⇒ Object
- .registry ⇒ Object
Instance Method Summary collapse
-
#cookies ⇒ Object
ArrayConsently::Cookie - what this tag leaves in the browser.
- #google? ⇒ Boolean
-
#initialize(**options) ⇒ Base
constructor
A new instance of Base.
-
#noscript ⇒ Object
Rendered inside
, for vendors that still ship a -
#scripts ⇒ Object
ArrayConsently::Script.
- #to_s ⇒ Object
Constructor Details
#initialize(**options) ⇒ Base
Returns a new instance of Base.
60 61 62 63 64 65 |
# File 'lib/consently/providers/base.rb', line 60 def initialize(**) @options = @category = ([:category] || self.class.default_category).to_sym @key = ([:as] || self.class.provider_key).to_sym validate! end |
Class Attribute Details
.default_category ⇒ Object
Set by each subclass; where a vendor is unambiguous (Plausible does not touch cookies) it can say :necessary and load right away.
36 37 38 |
# File 'lib/consently/providers/base.rb', line 36 def default_category @default_category end |
.google=(value) ⇒ Object (writeonly)
Whether this vendor is one of Google's, which is what advanced consent mode is about: those tags may load before consent because they respect the denied defaults themselves.
28 29 30 |
# File 'lib/consently/providers/base.rb', line 28 def google=(value) @google = value end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
58 59 60 |
# File 'lib/consently/providers/base.rb', line 58 def category @category end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
58 59 60 |
# File 'lib/consently/providers/base.rb', line 58 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'lib/consently/providers/base.rb', line 58 def @options end |
Class Method Details
.build(key, **options) ⇒ Object
20 21 22 23 |
# File 'lib/consently/providers/base.rb', line 20 def build(key, **) klass = registry[key.to_sym] or raise UnknownProvider, key klass.new(**) end |
.cookie(name, days: nil) ⇒ Object
What this vendor stores in the visitor's browser, for the policy
page. days: nil means a session cookie.
49 50 51 |
# File 'lib/consently/providers/base.rb', line 49 def (name, days: nil) << { name: name, days: days } end |
.cookie_manifest ⇒ Object
53 54 55 |
# File 'lib/consently/providers/base.rb', line 53 def @cookie_manifest ||= [] end |
.google? ⇒ Boolean
30 31 32 |
# File 'lib/consently/providers/base.rb', line 30 def google? !!@google end |
.provider_key ⇒ Object
38 39 40 |
# File 'lib/consently/providers/base.rb', line 38 def provider_key @provider_key end |
.provider_key=(key) ⇒ Object
42 43 44 45 |
# File 'lib/consently/providers/base.rb', line 42 def provider_key=(key) @provider_key = key.to_sym register(@provider_key, self) end |
.register(key, klass) ⇒ Object
16 17 18 |
# File 'lib/consently/providers/base.rb', line 16 def register(key, klass) registry[key.to_sym] = klass end |
.registry ⇒ Object
12 13 14 |
# File 'lib/consently/providers/base.rb', line 12 def registry @@registry ||= {} end |
Instance Method Details
#cookies ⇒ Object
ArrayConsently::Cookie - what this tag leaves in the browser.
77 78 79 |
# File 'lib/consently/providers/base.rb', line 77 def self.class..map { |attributes| Cookie.new(**attributes, provider: key) } end |
#google? ⇒ Boolean
72 73 74 |
# File 'lib/consently/providers/base.rb', line 72 def google? self.class.google? end |
#noscript ⇒ Object
Rendered inside
, for vendors that still ship a
83 84 85 |
# File 'lib/consently/providers/base.rb', line 83 def noscript nil end |
#scripts ⇒ Object
ArrayConsently::Script
68 69 70 |
# File 'lib/consently/providers/base.rb', line 68 def scripts [] end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/consently/providers/base.rb', line 87 def to_s "#{key} (#{category})" end |