Skip to content

Commit

Permalink
allow base64 encoding of ga4 user env, fix user stat collection nil b…
Browse files Browse the repository at this point in the history
…ug (#6889)
  • Loading branch information
orangewolf authored Aug 15, 2024
1 parent 891cdb5 commit 69f0b81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/services/hyrax/analytics/ga4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@ def valid?
REQUIRED_KEYS.all? { |required| @config[required].present? }
end

def base64?(value)
value.is_a?(String) && Base64.strict_encode64(Base64.decode64(value)) == value
end

def account_json_string
@account_json ||= @config['account_json'] || File.read(@config['account_json_path'])
return @account_json_string if @account_json_string
@account_json_string = if @config['account_json']
base64?(@config['account_json']) ? Base64.decode64(@config['account_json']) : @config['account_json']
else
File.read(@config['account_json_path'])
end
end

def account_info
Expand Down
2 changes: 1 addition & 1 deletion app/services/hyrax/user_stat_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def tally_results(current_stats, stat_name, total_stats)

date_key = stats.date.to_s
old_count = total_stats[date_key] ? total_stats[date_key].fetch(stat_name) { 0 } : 0
new_count = old_count + stats.method(stat_name).call
new_count = old_count + stats.method(stat_name).call.to_i

old_values = total_stats[date_key] || {}
total_stats.store(date_key, old_values)
Expand Down

0 comments on commit 69f0b81

Please sign in to comment.