Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Fix integrations object key for Amplitude (Actions) #307

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bobbyatsegment
Copy link

Fix for issue #296

Currently, when integrations.All is false and integrations.Actions Amplitude is true, the latter field will be replaced by the session_id that is generated for this destination, resulting in events not reaching Amplitude (Actions).

This can be replicated by enabling an instance of Amplitude (Actions), sending an event with integrations.Actions Amplitude set to true, and observing both the outbound request payload and how the event populates in the source's debugger:

Invoking event from source:
Screen Shot 2023-03-07 at 2 43 38 PM

Outbound request payload:
Screen Shot 2023-03-07 at 2 43 51 PM

Event populating in Source Debugger:
Screen Shot 2023-03-07 at 2 44 04 PM

This results in the event not sending to Amplitude.

When integrations.Amplitude (Actions): true is part of the event invoked from the client, it takes precedence over integrations.Actions Amplitude.session_id and the event will deliver to Amplitude as expected, albeit without the session ID:

Invoking event from source:
Screen Shot 2023-03-07 at 2 44 20 PM

Outbound request payload:
Screen Shot 2023-03-07 at 2 44 41 PM

Event populating in Source Debugger:
Screen Shot 2023-03-07 at 2 44 49 PM

Currently, when fetchDestinationForWriteKey is invoked, the destination name for Amplitude (Actions) is changed to the creation name Actions Amplitude, and the session_id will take precedence and override the boolean that is being set in the integrations object, as with the first example.

Added an update to fetchDestinationForWriteKey so that the destination name is set as destination.id if the destination name is "Amplitude (Actions)". With this change, the integrations object should now get set to integrations.Amplitude (Actions) and deliver events to Amplitude as expected, as with the second example.

session_id can then be passed to an event’s payload by pulling the value from localStorage.analytics_session_id and setting it in the properties or traits object:

Session ID as a property:
Screen Shot 2023-03-07 at 2 45 19 PM

Both the event and Session ID get sent to Amplitude:
Screen Shot 2023-03-07 at 2 45 38 PM

Added a section called "Destination Considerations" in the readme that mentions this process.

@enjoyjeremy-bc
Copy link

Hi @bobbyatsegment , thanks for this PR! I'm looking into workarounds for this issue and am not sure that manual adding the session_id to all page and track events will be scalable for my team.
Would it be possible to use the fetchDestinationForWriteKey() function to populate the integrations object with the session ID? "Actions Amplitude": { "session_id": 1678894951273 }

@samuelhorn
Copy link

This seems like the same problem we have investigated this week, where Segment -> Amplitude works fine with just the default Segment script tag, but events only landing in Segment with Consent Manager. Only difference seems to be the integrations object.

I agree with what @enjoyjeremy-bc says, would be great if this could be automatically included.
This is currently blocking us from switching to Segment and Amplitude tracking on our website.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants