From 77535e6135444c463d67e76708413c2996757bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Durrit=C3=A7ague?= Date: Tue, 17 Oct 2023 10:16:50 +0200 Subject: [PATCH] Add groups to identification --- lib/amplitude_api.rb | 5 +++-- lib/amplitude_api/identification.rb | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/amplitude_api.rb b/lib/amplitude_api.rb index 8fc285f..af19516 100644 --- a/lib/amplitude_api.rb +++ b/lib/amplitude_api.rb @@ -94,11 +94,12 @@ def track(*events) # ==== Identification related methods - def send_identify(user_id, device_id, user_properties = {}) + def send_identify(user_id, device_id, user_properties = {}, groups = []) identification = AmplitudeAPI::Identification.new( user_id: user_id, device_id: device_id, - user_properties: user_properties + user_properties: user_properties, + groups: groups ) identify(identification) end diff --git a/lib/amplitude_api/identification.rb b/lib/amplitude_api/identification.rb index 36da892..99f8e52 100644 --- a/lib/amplitude_api/identification.rb +++ b/lib/amplitude_api/identification.rb @@ -12,16 +12,20 @@ class Identification # @!attribute [ rw ] user_properties # @return [ String ] the user_properties to be attached to the Amplitude Identify attr_accessor :user_properties + # @!attribute [ rw ] groups + # @return [ String ] the groups to be attached to the Amplitude Identify + attr_accessor :groups # Create a new Identification # # @param [ String ] user_id a user_id to associate with the identification # @param [ String ] device_id a device_id to associate with the identification # @param [ Hash ] user_properties various properties to attach to the user identification - def initialize(user_id: "", device_id: nil, user_properties: {}) + def initialize(user_id: "", device_id: nil, user_properties: {}, groups: []) self.user_id = user_id - self.device_id = device_id if device_id + self.device_id = device_id self.user_properties = user_properties + self.groups = groups end def user_id=(value) @@ -39,8 +43,10 @@ def user_id=(value) def to_hash { user_id: user_id, + device_id: device_id, + groups: groups, user_properties: user_properties - }.tap { |hsh| hsh[:device_id] = device_id if device_id } + }.compact end # @return [ true, false ]