-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Send initialisation event with version and config * Update docs for anynonimsing data and pushing tags to github * Actioned review comments * Action review comment: change terminlogy anonymise -> pseudonymise * Delay sending of initialise event until after startup and until first event triggered * Remove unecessary spec expectations when initialise event not posted
- Loading branch information
Showing
12 changed files
with
248 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
module DfE | ||
module Analytics | ||
# DfE Analytics initialisation event | ||
# - Event should only be sent once, but NOT on startup as this causes errors on some services | ||
# - Event contains the dfe analytics version, config and other items | ||
class Initialise | ||
# Disable rubocop class variable warnings for class - class variable required to control sending of event | ||
# rubocop:disable Style:ClassVars | ||
@@initialise_event_sent = false # rubocop:disable Style:ClassVars | ||
|
||
def self.trigger_initialise_event | ||
new.send_initialise_event | ||
end | ||
|
||
def self.initialise_event_sent? | ||
@@initialise_event_sent | ||
end | ||
|
||
def self.initialise_event_sent=(value) | ||
@@initialise_event_sent = value # rubocop:disable Style:ClassVars | ||
end | ||
|
||
def send_initialise_event | ||
return unless DfE::Analytics.enabled? | ||
|
||
initialise_event = DfE::Analytics::Event.new | ||
.with_type('initialise_analytics') | ||
.with_data(initialisation_data) | ||
.as_json | ||
|
||
if DfE::Analytics.async? | ||
DfE::Analytics::SendEvents.perform_later([initialise_event]) | ||
else | ||
DfE::Analytics::SendEvents.perform_now([initialise_event]) | ||
end | ||
|
||
@@initialise_event_sent = true # rubocop:disable Style:ClassVars | ||
end | ||
|
||
private | ||
|
||
def initialisation_data | ||
{ | ||
analytics_version: DfE::Analytics::VERSION, | ||
config: { | ||
pseudonymise_web_request_user_id: DfE::Analytics.config.pseudonymise_web_request_user_id | ||
} | ||
} | ||
end | ||
# rubocop:enable Style:ClassVars | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe DfE::Analytics::Initialise do | ||
before do | ||
allow(DfE::Analytics::SendEvents).to receive(:perform_later) | ||
allow(DfE::Analytics).to receive(:enabled?).and_return(true) | ||
end | ||
|
||
describe 'trigger_initialise_event ' do | ||
it 'includes the expected attributes' do | ||
described_class.trigger_initialise_event | ||
|
||
expect(DfE::Analytics::SendEvents).to have_received(:perform_later) | ||
.with([a_hash_including({ | ||
'event_type' => 'initialise_analytics', | ||
'data' => [ | ||
{ 'key' => 'analytics_version', 'value' => [DfE::Analytics::VERSION] }, | ||
{ 'key' => 'config', | ||
'value' => ['{"pseudonymise_web_request_user_id":false}'] } | ||
] | ||
})]) | ||
end | ||
end | ||
|
||
describe '.initialise_event_sent=' do | ||
it 'allows setting of the class variable' do | ||
described_class.initialise_event_sent = true | ||
expect(described_class.initialise_event_sent?).to eq(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.