Skip to main content

I am using NodeJS SDK to insert events and event_properties using HTTP API v2, and user_properites using identify

My sample code block looks as below

import { Identify } from '@amplitude/identify'

import * as Amplitude from '@amplitude/node'

const client = Amplitude.init(amplitude_api);

const identify = new Identify();

const payload ={event_type: eventType,

device_id: row.deviceid,

user_id: row.userid,

event_properties: row,

event_date: moment(row.timestamp).format('YYYY-MM-DD'),

timestamp: new Date(row.timestamp),

update_timestamp:new Date().toISOString(),

context: {ip: row.ipaddress},

// "user_properties": {

// user_id: row.userid,

// device_id: row.deviceid,

// partner_id: row.partnerid,

// slotid: row.slotid

// },

}

identify.set('user_id', row.userid).set('device_id',row.deviceid)

const userProperties = {'partner_id':row.partner_id as string,'osname':row.osname,'devicetype': row.devicetype}

identify.append('partner_id',row.partner_id as string) 

const identifyEvent = identify.identifyUser('user_id','device_id')

client.logEvent(identifyEvent);

client.logEvent(payload)

 

Questions:

  1. It looks like I don’t have to use identify API for user_properties as we can pass these with events itself (client.logEvent(payload)) . Is this assumption correct. I have commented the user_properties in my code for now but I could get the user_id, device_id, partner_id and slotid inserted into user_properties of Amplitude just fine. Is this a good way to implement this or should I have to look at other ways like insert into identify end point before event endpoint
  2. If I need to user identify I could only pass user_id, device_id into the “const identifyEvent = identify.identifyUser('user_id','device_id')”. Any third value is not allowed here. I also tried to append to identify using “identify.append('partner_id',row.partner_id as string) “, doesn’t seem to work as well
  3. So if I need to use identify how can I ingest more user_properties other than just user_id and device_id
  4. How can run my segment reports based on event_date instead of insert date in the default date option available. Screenshot attached
  5. How can I filter using between clause in for dates or any other attribute in where condition. Screenshot attached
  6.  

Hi dakkineni,

  1. Yes you can pass user properties with the events themselves, you do not actually have to send them in a separate Identify call!
  2. What is this partner_id value you are trying to pass? In Amplitude we recognise three identifiers: https://help.amplitude.com/hc/en-us/articles/115003135607#h_7cf7c47f-ec71-4e15-8c47-a2bda5d84186 Since amplitude_ID is a combi taken from user_id and device_id, it makes sense that a third value is not needed/allowed
  3. An example code should look like this: curl --data 'api_key=API_KEY' --data 'identification=o{"user_id":"datamonster@gmail.com", "user_properties":{"Age":"35"}, "country":"United States"}]' https://api.amplitude.com/identify (as found on https://developers.amplitude.com/docs/identify-api) - the user properties should be appended after the user_properties function
  4. Is event_date a property you are sending with your events from Segment? If it is, it should show up as an event property that you can select (replacing the “timestamp” property)

Hi dakkineni,

  1. Yes you can pass user properties with the events themselves, you do not actually have to send them in a separate Identify call!
  2. What is this partner_id value you are trying to pass? In Amplitude we recognise three identifiers: https://help.amplitude.com/hc/en-us/articles/115003135607#h_7cf7c47f-ec71-4e15-8c47-a2bda5d84186 Since amplitude_ID is a combi taken from user_id and device_id, it makes sense that a third value is not needed/allowed
  3. An example code should look like this: curl --data 'api_key=API_KEY' --data 'identification=o{"user_id":"datamonster@gmail.com", "user_properties":{"Age":"35"}, "country":"United States"}]' https://api.amplitude.com/identify (as found on https://developers.amplitude.com/docs/identify-api) - the user properties should be appended after the user_properties function
  4. Is event_date a property you are sending with your events from Segment? If it is, it should show up as an event property that you can select (replacing the “timestamp” property)

Thank-you Ning,

Let me try a few options and get back to you

Thanks

Deepika


You’re very welcome Deepika 🙂 I hope you manage to resolve it, if not, let me know, we’re here to help!


Reply