GA4 integration for conversion event I'm trying to...
# support
a
GA4 integration for conversion event I'm trying to set the clientId, sessionId and userId in GA server conversion event so that I can accurately attribute conversions to web sessions. I set an integration object with clientId and sessionId (screenshot 1). However, in the GA4 event that gets sent (screenshot 2): user_id = RS userID client_id =RS rudderID (ignoring what gets sent through in the integration object) session_id = Not sent, again integration object is ignored. What's the latest documentation in terms of GA4 (Nod SDK server enet) when it comes to user_id, session_id and client_id and how to set them?
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
a
To expand, the outcome I'm looking for is: • GA4 user_id = Rudderstack UserId • GA4 client_id = GA client_id from the _ga cookie (which we will persist and pass to the back-end for this event to be stitched to the FE events captured in device mode) • GA4 session_id = Rudderstack sessionId provided by Rudderstack SDK on FE (and stored and passed to back-end for this event, same as clientId above).
Hi @shy-kite-21035, just checking if you have anything you can share on this one?
m
Hi David, so my understanding is that you want to do the following - Use the client_id set in the front-end (device-mode) - Send a backend event and associate this event with the same user - Get correct attribution for the backend event. If this understanding is correct than this can be done. For your backend event you will have to send the client_id and the session_id
s
Your event will look more like this
Copy code
rudderanalytics.track(
  "Promotion Viewed", {
    creative: "Summer Banner",
    position: "featured_app_1",
    promotion_id: "P_12345",
    name: "Summer Sale",
    products: [{
      product_id: "507f1f77bcf86cd799439011",
      name: "Monopoly: 3rd Edition",
      coupon: "SUMMER_FUN",
      category: "Apparel",
      brand: "Google",
      variant: "green",
      price: "19",
      quantity: "2",
      position: "0",
      affiliation: "Google Merchandise Store",
      currency: "USD",
      discount: 2.22,
    }, ],
  }, {
    externalId: [{
      type: "ga4ClientId",
      id: "client_id",
    }, ],
  }
);
Notice: How the clientId is sent as an external id. You will also need to pass the sessionId to the event that you are sending from your backend. Make sure the pass the clientId and sessionId to your NodeJs backend and then pass the fields to GA4. Also your sessionId would be in context.traits. See docs
a
OK thank you. I'l try this and let you know if it works
Should the externalId object be at the top level of the Rudderstack payload or in the properties? When I send it through, the GA4 mapped event still uses the user)id as the client_id
Looking at the rudder-sdk-node, are you use it's externalId and not the integrations object?
m
That is correct, the externalId should be in the context object. See sample
s
Copy code
client.track({
  userId: "123456",
  event: "sometjing_done",
  properties: {
    abc: {},
    revenue: 19.95,
    shippingMethod: "Premium",
  },
  context: {
    externalId: [{
      type: "ga4ClientId",
      id: "f0dd99b6f979fb551ce583373900f937"
    }],
  }
})
a
Thank you! And just to confirm, we should set the session_id for server-side to the session_id from the _ga cookie itself? I assume the RS generated session_id will be different when running GA4 in client mode?
m
You should pass the sessionId (the one generated by gtag) from the client side and pass it to the server. Then use this sessionId and pass it in the server events. RudderStack uses the same session id (generated by gtag) in the device mode. https://www.rudderstack.com/docs/destinations/streaming-destinations/google-analytics-4/setup-guide/#connection-mode-comparison
gratitude thank you 1