managed-components / hubspot

Managed Component for Hubspot
Other
1 stars 2 forks source link

Send events on the server-side #3

Open Manouchehri opened 1 year ago

Manouchehri commented 1 year ago

Tested locally, works fine. The user-agent was required, otherwise events were not coming through.

bjesus commented 1 year ago

Do you know if this is officially supported by their API? it seems like the IP address isn't forwarded for events, meaning HubSpot might consider the request to be coming from a different place. For forms we have ipAddress: event.client.ip, but I can't see anything similar on events.

Manouchehri commented 1 year ago

The __ptq.gif API endpoint isn't officially supported to begin with. 😅 Closest I could find was https://legacydocs.hubspot.com/docs/methods/enterprise_events/http_api.

We could add an x-forwarded-for header.

Manouchehri commented 1 year ago

@bjesus The code has been reformatted as requested.

bjesus commented 1 year ago

Thanks @Manouchehri , but I'm afraid we can't merge this. Managed Components that are using an unofficial API are the result of reverse engineering client-side pixels and replicating their behavior. We cannot assume that if we send the same request server-side, without 3rd-party cookies and without the origin IP, it will work just the same (if we've done that, Zaraz would never make client-side requests, and 50% of the tools would have been broken...). We also cannot assume that Hubspot is reading a specific HTTP header.

Putting aside that I too wish things worked this way, do you have any reason to think this works? Have you tested this? Are IPs being recorded correctly?

Manouchehri commented 1 year ago

do you have any reason to think this works? Have you tested this? Are IPs being recorded correctly?

Looks like it's working to me. I've also gone ahead in in 2b89361a29b45763e7a02441732dc55aa4173fdd and added the extra documented headers that HubSpot recommends.

https://developers.hubspot.com/docs/cms/developer-reference/reverse-proxy-support#general-instructions

https://community.hubspot.com/t5/CMS-Development/Lessons-Learned-from-Setting-up-a-Reverse-Proxy-With-HubSpot-CMS/td-p/435961

image image
bjesus commented 1 year ago

Thanks for checking @Manouchehri !

As for tracking events - can you confirm that your real location isn't cayman islands? I mean, is it clear that HTTP header is spoofing the origin IP of the request?

For forms - I've talked with @Refaerds from the team and we're a little confused - what kind of forms are you trying to track? Are these forms built inside Hubspot, or forms on your website that you want Hubspot to track? It seems like the endpoint you want to use is meant for the former, while the original form event in Zaraz is meant for tracking the latter.

Manouchehri commented 1 year ago

It seems like the endpoint you want to use is meant for the former, while the original form event in Zaraz is meant for tracking the latter.

I was using the older Zaraz HubSpot tool for this just fine.

bjesus commented 1 year ago

Indeed it looks like we had a naming issue when converting our code to a Managed Component because we named both events the same, but they're doing something different: one is tracking forms created by Hubspot and the other is tracking normal forms on the website. I'm still trying to understand - what kind of form are you trying to track? I suspect things broke when you converted not because the code is wrong, but because it now supports the other type of forms. If that's the case, we shouldn't remove or change the current handler, and instead we should add another that works like the previous implementation.

Manouchehri commented 1 year ago

what kind of form are you trying to track?

Forms created by HubSpot.

As for tracking events - can you confirm that your real location isn't cayman islands? I mean, is it clear that HTTP header is spoofing the origin IP of the request?

It is my real location.

Hmm, how about we add a flag or something with a warning that server-side tracking events won't be as accurate?

Manouchehri commented 11 months ago

So thanks to https://github.com/managed-components/create-managed-component, I've started to run this fork on our website to see what happens in production.

Interestingly it seems like the conversion info metadata (which is created from the IP address) is left blank during my last test. (Which is better than wrong info IMO.)

Let's keep this open for now and I'll report back in a few weeks to see how it works out long-term. =)

kuba-orlik commented 10 months ago

Both types of forms should be supported with this here Hubspot MC now. Could you let us know if the current version works for you?

websirnik commented 3 weeks ago

@Manouchehri @bjesus , is server-side pageview tracking feasible as a result? Is it only the metadata, like location, that is missing, or is there anything else?

Manouchehri commented 3 weeks ago

@Manouchehri @bjesus , is server-side pageview tracking feasible as a result? Is it only the metadata, like location, that is missing, or is there anything else?

Just location is missing. Aside from that, works perfectly.