itly-plugin-snowplow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 779553f73b44ead11e1d4b49e4614c4153102013a2546815ce577844b1de1384
4
+ data.tar.gz: c301b0f5f83964bd074627f29fb161485e6b14ccf698457ca147859d51e9dc0c
5
+ SHA512:
6
+ metadata.gz: 4875fe0a940a56388daa2cdfe627a69117d7e4ef9d8cd52a946572c8ddc2eb2b02a37fe20cb347add3d30aec32b2a499485f78036e64bdbc1e8605a601d1c6b7
7
+ data.tar.gz: 59c579f660e7e1988f523c5d18b594187dd37b67e894ead091f59c658de1902ce679c1b72a55fda6ce9c9bab65b8a44fd8ca6b549899dfdc3ca282a62e87492b
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in itly-plugin-snowplow.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ if ENV['LOCAL_ITLY_GEM']
11
+ # TODO: before publication to RubyGems, switch to version 1
12
+ gem 'itly-sdk', '~> 0.1', path: '../sdk'
13
+ end
14
+
15
+ gem 'rbs', '~> 1.0'
16
+ gem 'rspec'
17
+ gem 'steep', '~> 0.41'
data/Steepfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ signature 'sig'
5
+
6
+ check 'lib'
7
+
8
+ library 'logger', 'set', 'itly-sdk'
9
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'itly/plugin-snowplow'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Configure and load RBS
5
+ unless ENV['DISABLE_TYPE_CHECKING']
6
+ ENV['RBS_TEST_TARGET'] = 'Itly::*'
7
+ ENV['RBS_TEST_LOGLEVEL'] = 'warn'
8
+ ENV['RBS_TEST_DOUBLE_SUITE'] = 'rspec'
9
+ ENV['RBS_TEST_OPT'] = '-I./sig -I../sdk/sig'
10
+
11
+ require 'rbs/test/setup'
12
+ end
13
+
14
+ # Start RSpec
15
+ require 'rspec/core'
16
+
17
+ ENV['RSPEC_RUN_FROM_SCRIPT'] = 'true'
18
+ RSpec::Core::Runner.invoke
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/itly/plugin/snowplow/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'itly-plugin-snowplow'
7
+ spec.version = Itly::Plugin::Snowplow::VERSION
8
+ spec.authors = ['Iteratively', 'Benjamin Bouchet', 'Justin Fiedler', 'Andrey Sokolov']
9
+ spec.email = ['support@iterative.ly']
10
+
11
+ spec.summary = 'Snowplow plugin for Iteratively SDK for Ruby'
12
+ spec.description = 'Track and validate analytics with a unified, extensible interface ' \
13
+ 'that works with all your 3rd party analytics providers.'
14
+ spec.homepage = 'https://github.com/iterativelyhq/itly-sdk-ruby'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/iterativelyhq/itly-sdk-ruby/plugin-snowplow'
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'itly-sdk', '~> 0.1'
31
+ spec.add_dependency 'snowplow-tracker', '~> 0.6'
32
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['LOCAL_ITLY_GEM']
4
+ lib = File.expand_path('../../../sdk/lib', File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ end
7
+
8
+ require_relative 'plugin/snowplow/snowplow'
9
+ require_relative 'plugin/snowplow/context'
10
+ require_relative 'plugin/snowplow/call_options'
11
+ require_relative 'plugin/snowplow/options'
12
+ require_relative 'plugin/snowplow/version'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Itly
4
+ class Plugin
5
+ # Snowplow plugin class for Itly SDK
6
+ class Snowplow
7
+ ##
8
+ # Snowplow specific plugin options class
9
+ #
10
+ class CallOptions < Itly::PluginCallOptions
11
+ end
12
+
13
+ ##
14
+ # Snowplow specific plugin options class for calls to +page+
15
+ #
16
+ class PageOptions < CallOptions
17
+ attr_reader :contexts, :callback
18
+
19
+ def initialize(contexts: nil, callback: nil)
20
+ super()
21
+ @contexts = contexts
22
+ @callback = callback
23
+ end
24
+
25
+ def to_s
26
+ class_name = self.class.name.split('::').last
27
+ contexts_str = contexts.nil? ? 'nil' : "[#{contexts.collect(&:to_s).join ', '}]"
28
+ "#<Snowplow::#{class_name} contexts: #{contexts_str} callback: #{callback.nil? ? 'nil' : 'provided'}>"
29
+ end
30
+ end
31
+
32
+ ##
33
+ # Snowplow specific plugin options class for calls to +track+
34
+ #
35
+ class TrackOptions < CallOptions
36
+ attr_reader :contexts, :callback
37
+
38
+ def initialize(contexts: nil, callback: nil)
39
+ super()
40
+ @contexts = contexts
41
+ @callback = callback
42
+ end
43
+
44
+ def to_s
45
+ class_name = self.class.name.split('::').last
46
+ contexts_str = contexts.nil? ? 'nil' : "[#{contexts.collect(&:to_s).join ', '}]"
47
+ "#<Snowplow::#{class_name} contexts: #{contexts_str} callback: #{callback.nil? ? 'nil' : 'provided'}>"
48
+ end
49
+ end
50
+
51
+ ##
52
+ # Snowplow specific plugin options class for calls to plugin methods
53
+ #
54
+ %w[Identify Group Alias].each do |name|
55
+ class_eval(
56
+ <<-EVAL, __FILE__, __LINE__ + 1
57
+ class #{name}Options < CallOptions # class IdentifyOptions < CallOptions
58
+ end # end
59
+ EVAL
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Itly
4
+ class Plugin
5
+ class Snowplow
6
+ ##
7
+ # Snowplow context to be used by CallOptions
8
+ #
9
+ class Context
10
+ attr_reader :schema, :data
11
+
12
+ def initialize(schema:, data:)
13
+ @schema = schema
14
+ @data = data
15
+ end
16
+
17
+ def to_self_describing_json
18
+ SnowplowTracker::SelfDescribingJson.new schema, data
19
+ end
20
+
21
+ def to_s
22
+ "#<Snowplow::Context schema: #{schema} data: #{data}>"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'itly-sdk'
4
+
5
+ class Itly
6
+ class Plugin
7
+ class Snowplow
8
+ ##
9
+ # Options for the Snowplow plugin class
10
+ #
11
+ class Options
12
+ attr_reader :endpoint, :protocol, :method, :buffer_size, :disabled
13
+
14
+ ##
15
+ # Instantiate a new Options
16
+ #
17
+ # @param [String] endpoint: specify the Snowplow endpoint
18
+ # @param [String] protocol: specify the protocol to connect to the Snowplow endpoint.
19
+ # Can be 'http' or 'https'. Default to 'http'
20
+ # @param [String] method: specify the HTTP verb to use when sending events to the Snowplow endpoint.
21
+ # Can be 'get' or 'post'. Default to 'get'
22
+ # @param [Integer] buffer_size: specify the buffer size before flushing event to the Snowplow endpoint.
23
+ # Leave it to +nil+ to set it's default value. Default to 1 for GET method, and 10 for POST
24
+ # @param [TrueClass/FalseClass] disabled: set to true to disable the plugin. Default to false
25
+ #
26
+ def initialize(endpoint:, protocol: 'http', method: 'get', buffer_size: nil, disabled: false)
27
+ super()
28
+ @endpoint = endpoint
29
+ @protocol = protocol
30
+ @method = method
31
+ @buffer_size = buffer_size
32
+ @disabled = disabled
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,154 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'itly-sdk'
4
+ require 'snowplow-tracker'
5
+
6
+ class Itly
7
+ class Plugin
8
+ ##
9
+ # Snowplow plugin class for Itly SDK
10
+ #
11
+ class Snowplow < Plugin
12
+ attr_reader :logger, :vendor, :disabled, :client
13
+
14
+ ##
15
+ # Instantiate a new Plugin::Snowplow
16
+ #
17
+ # @param [String] vendor: the Snowplow vendor
18
+ # @param [Itly::Plugin::Snowplow::Options] options: the options. See +Itly::Plugin::Snowplow::Options+
19
+ #
20
+ def initialize(vendor:, options:)
21
+ super()
22
+ @vendor = vendor
23
+ @disabled = options.disabled
24
+
25
+ emitter = SnowplowTracker::Emitter.new \
26
+ options.endpoint, protocol: options.protocol, method: options.method, buffer_size: options.buffer_size
27
+ @client = SnowplowTracker::Tracker.new emitter
28
+ end
29
+
30
+ ##
31
+ # Initialize Snowplow plugin
32
+ #
33
+ # @param [Itly::PluginOptions] options: plugin options
34
+ #
35
+ def load(options:)
36
+ super
37
+ # Get options
38
+ @logger = options.logger
39
+
40
+ # Log
41
+ logger&.info "#{id}: load()"
42
+
43
+ logger&.info "#{id}: plugin is disabled!" if @disabled
44
+ end
45
+
46
+ ##
47
+ # Identify a user
48
+ #
49
+ # Raise an error if the client fails
50
+ #
51
+ # @param [String] user_id: the id of the user in your application
52
+ # @param [Hash] properties: unused
53
+ # @param [Itly::Plugin::Snowplow::IdentifyOptions] options: the plugin specific options
54
+ #
55
+ def identify(user_id:, properties: nil, options: nil)
56
+ super
57
+ return unless enabled?
58
+
59
+ # Log
60
+ log = Itly::Loggers.vars_to_log user_id: user_id, options: options
61
+ logger&.info "#{id}: identify(#{log})"
62
+
63
+ # Send through the client
64
+ client.set_user_id user_id
65
+ end
66
+
67
+ ##
68
+ # Record page views
69
+ #
70
+ # Raise an error if the client fails
71
+ #
72
+ # @param [String] user_id: the id of the user in your application
73
+ # @param [String] category: the category of the page
74
+ # @param [String] name: the name of the page.
75
+ # @param [Hash] properties: the properties to pass to your application
76
+ # @param [Itly::Plugin::Snowplow::PageOptions] options: the plugin specific options
77
+ #
78
+ def page(user_id:, category: nil, name: nil, properties: nil, options: nil)
79
+ super
80
+ return unless enabled?
81
+
82
+ # Log
83
+ log = Itly::Loggers.vars_to_log(
84
+ user_id: user_id, category: category, name: name, properties: properties, options: options
85
+ )
86
+ logger&.info "#{id}: page(#{log})"
87
+
88
+ # Identify the user
89
+ client.set_user_id user_id
90
+
91
+ # Send through the client
92
+ contexts = nil
93
+ if options&.contexts.is_a?(Array) && options.contexts.any?
94
+ contexts = options.contexts.collect(&:to_self_describing_json)
95
+ end
96
+
97
+ client.track_screen_view name, nil, contexts
98
+ end
99
+
100
+ ##
101
+ # Track an event
102
+ #
103
+ # Raise an error if the client fails
104
+ #
105
+ # @param [String] user_id: the id of the user in your application
106
+ # @param [Event] event: the Event object to pass to your application
107
+ # @param [Itly::Plugin::Snowplow::TrackOptions] options: the plugin specific options
108
+ #
109
+ def track(user_id:, event:, options: nil)
110
+ super
111
+ return unless enabled?
112
+
113
+ # Log
114
+ log = Itly::Loggers.vars_to_log(
115
+ user_id: user_id, event: event&.name, version: event&.version, properties: event&.properties, options: options
116
+ )
117
+ logger&.info "#{id}: track(#{log})"
118
+
119
+ # Identify the user
120
+ client.set_user_id user_id
121
+
122
+ # Send through the client
123
+ schema_version = event.version&.gsub(/\./, '-')
124
+ schema = "iglu:#{vendor}/#{event.name}/jsonschema/#{schema_version}"
125
+
126
+ event_json = SnowplowTracker::SelfDescribingJson.new(
127
+ schema, event.properties
128
+ )
129
+
130
+ contexts = nil
131
+ if options&.contexts.is_a?(Array) && options.contexts.any?
132
+ contexts = options.contexts.collect(&:to_self_describing_json)
133
+ end
134
+
135
+ client.track_self_describing_event event_json, contexts
136
+ end
137
+
138
+ ##
139
+ # Get the plugin ID
140
+ #
141
+ # @return [String] plugin id
142
+ #
143
+ def id
144
+ 'snowplow'
145
+ end
146
+
147
+ private
148
+
149
+ def enabled?
150
+ !@disabled
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Itly
4
+ class Plugin
5
+ class Snowplow < Plugin
6
+ VERSION = '0.1.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,39 @@
1
+ class Itly
2
+ class Plugin
3
+ class Snowplow
4
+ class CallOptions < Itly::PluginCallOptions
5
+ end
6
+
7
+ class PageOptions < CallOptions
8
+ attr_reader contexts: Array[Itly::Plugin::Snowplow::Context]?
9
+ attr_reader callback: (^(Integer?, String?) -> void)?
10
+
11
+ def to_s: () -> String
12
+
13
+ private
14
+
15
+ def initialize: (?contexts: Array[Itly::Plugin::Snowplow::Context]? contexts, ?callback: (^(Integer?, String?) -> void)? callback) -> void
16
+ end
17
+
18
+ class TrackOptions < CallOptions
19
+ attr_reader contexts: Array[Itly::Plugin::Snowplow::Context]?
20
+ attr_reader callback: (^(Integer?, String?) -> void)?
21
+
22
+ def to_s: () -> String
23
+
24
+ private
25
+
26
+ def initialize: (?contexts: Array[Itly::Plugin::Snowplow::Context]? contexts, ?callback: (^(Integer?, String?) -> void)? callback) -> void
27
+ end
28
+
29
+ class IdentifyOptions < CallOptions
30
+ end
31
+
32
+ class GroupOptions < CallOptions
33
+ end
34
+
35
+ class AliasOptions < CallOptions
36
+ end
37
+ end
38
+ end
39
+ end
data/sig/context.rbs ADDED
@@ -0,0 +1,17 @@
1
+ class Itly
2
+ class Plugin
3
+ class Snowplow
4
+ class Context
5
+ attr_reader schema: String
6
+ attr_reader data: Hash[String, untyped]
7
+
8
+ def to_self_describing_json: () -> SnowplowTracker::SelfDescribingJson
9
+ def to_s: () -> String
10
+
11
+ private
12
+
13
+ def initialize: (schema: String schema, data: Hash[String, untyped] data) -> void
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ # Part of the gems
2
+ class SnowplowTracker
3
+ class Tracker
4
+ end
5
+
6
+ class SelfDescribingJson
7
+ end
8
+ end
data/sig/options.rbs ADDED
@@ -0,0 +1,17 @@
1
+ class Itly
2
+ class Plugin
3
+ class Snowplow
4
+ class Options
5
+ attr_reader endpoint: String
6
+ attr_reader protocol: String
7
+ attr_reader method: String
8
+ attr_reader buffer_size: Integer?
9
+ attr_reader disabled: bool
10
+
11
+ private
12
+
13
+ def initialize: (endpoint: String endpoint, ?protocol: String protocol, ?method: String method, ?buffer_size: Integer buffer_size, ?disabled: bool disabled) -> void
14
+ end
15
+ end
16
+ end
17
+ end
data/sig/snowplow.rbs ADDED
@@ -0,0 +1,23 @@
1
+ class Itly
2
+ class Plugin
3
+ class Snowplow < Plugin
4
+ VERSION: String
5
+
6
+ attr_reader logger: Logger?
7
+ attr_reader vendor: String
8
+ attr_reader disabled: bool
9
+ attr_reader client: SnowplowTracker::Tracker
10
+
11
+ def load: (options: Itly::PluginOptions options) -> void
12
+ def identify: (user_id: String user_id, ?properties: propertiesHash? properties, ?options: Itly::Plugin::Snowplow::IdentifyOptions? options) -> void
13
+ def page: (user_id: String user_id, ?category: String? category, ?name: String? name, ?properties: propertiesHash? properties, ?options: Itly::Plugin::Segment::PageOptions? options) -> void
14
+ def track: (user_id: String user_id, event: Itly::Event event, ?options: Itly::Plugin::Snowplow::TrackOptions? options) -> void
15
+ def id: () -> String
16
+
17
+ private
18
+
19
+ def initialize: (vendor: String vendor, options: Itly::Plugin::Snowplow::Options options) -> void
20
+ def enabled?: () -> bool
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itly-plugin-snowplow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Iteratively
8
+ - Benjamin Bouchet
9
+ - Justin Fiedler
10
+ - Andrey Sokolov
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2021-06-15 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: itly-sdk
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: snowplow-tracker
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '0.6'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.6'
44
+ description: Track and validate analytics with a unified, extensible interface that
45
+ works with all your 3rd party analytics providers.
46
+ email:
47
+ - support@iterative.ly
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - ".rspec"
53
+ - Gemfile
54
+ - Steepfile
55
+ - bin/console
56
+ - bin/rspec
57
+ - bin/setup
58
+ - itly-plugin-snowplow.gemspec
59
+ - lib/itly/plugin-snowplow.rb
60
+ - lib/itly/plugin/snowplow/call_options.rb
61
+ - lib/itly/plugin/snowplow/context.rb
62
+ - lib/itly/plugin/snowplow/options.rb
63
+ - lib/itly/plugin/snowplow/snowplow.rb
64
+ - lib/itly/plugin/snowplow/version.rb
65
+ - sig/call_options.rbs
66
+ - sig/context.rbs
67
+ - sig/lib/snowplow_tracker.rbs
68
+ - sig/options.rbs
69
+ - sig/snowplow.rbs
70
+ homepage: https://github.com/iterativelyhq/itly-sdk-ruby
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ allowed_push_host: https://rubygems.org/
75
+ homepage_uri: https://github.com/iterativelyhq/itly-sdk-ruby
76
+ source_code_uri: https://github.com/iterativelyhq/itly-sdk-ruby/plugin-snowplow
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.6.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.3.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Snowplow plugin for Iteratively SDK for Ruby
96
+ test_files: []