From b44abb273ca41d7578dcb645f6951fc4b67c2e78 Mon Sep 17 00:00:00 2001 From: Mikko Karkee Date: Fri, 1 Dec 2023 08:57:38 +0200 Subject: [PATCH] Add origin to track different integration usage for metrics --- lib/phraseapp-in-context-editor-ruby.rb | 4 ++++ lib/phraseapp-in-context-editor-ruby/config.rb | 1 + lib/phraseapp-in-context-editor-ruby/view_helpers.rb | 1 + spec/phraseapp-in-context-editor-ruby/view_helpers_spec.rb | 6 ++++++ 4 files changed, 12 insertions(+) diff --git a/lib/phraseapp-in-context-editor-ruby.rb b/lib/phraseapp-in-context-editor-ruby.rb index bcc64d8..17a29b6 100644 --- a/lib/phraseapp-in-context-editor-ruby.rb +++ b/lib/phraseapp-in-context-editor-ruby.rb @@ -48,6 +48,10 @@ def enabled? def disabled? !config.enabled end + + def origin + config.origin + end end def self.configure diff --git a/lib/phraseapp-in-context-editor-ruby/config.rb b/lib/phraseapp-in-context-editor-ruby/config.rb index 7917318..052b0cf 100644 --- a/lib/phraseapp-in-context-editor-ruby/config.rb +++ b/lib/phraseapp-in-context-editor-ruby/config.rb @@ -9,6 +9,7 @@ class Config backend: PhraseApp::InContextEditor::BackendService.new, prefix: "{{__", suffix: "__}}" + origin: "in-context-editor-ruby" }.freeze CONFIG_OPTIONS.each do |option, default_value| diff --git a/lib/phraseapp-in-context-editor-ruby/view_helpers.rb b/lib/phraseapp-in-context-editor-ruby/view_helpers.rb index 2449714..dc09dad 100644 --- a/lib/phraseapp-in-context-editor-ruby/view_helpers.rb +++ b/lib/phraseapp-in-context-editor-ruby/view_helpers.rb @@ -18,6 +18,7 @@ def load_in_context_editor(opts = {}) "datacenter" => PhraseApp::InContextEditor.datacenter, "prefix" => PhraseApp::InContextEditor.prefix, "suffix" => PhraseApp::InContextEditor.suffix + "origin" => PhraseApp::InContextEditor.origin }.merge(opts) snippet = <<-EOS diff --git a/spec/phraseapp-in-context-editor-ruby/view_helpers_spec.rb b/spec/phraseapp-in-context-editor-ruby/view_helpers_spec.rb index b297fc9..d926e4b 100644 --- a/spec/phraseapp-in-context-editor-ruby/view_helpers_spec.rb +++ b/spec/phraseapp-in-context-editor-ruby/view_helpers_spec.rb @@ -37,6 +37,12 @@ class Helpers it { is_expected.to include("\"suffix\":\"__]]\"") } end + describe "origin setting" do + before(:each) { PhraseApp::InContextEditor.config.origin = "__]]" } + + it { is_expected.to include("\"origin\":\"in-context-editor-ruby\"") } + end + describe "overriding options" do let(:opts) { {prefix: "__%%"} } before(:each) { PhraseApp::InContextEditor.config.prefix = "__]]" }