Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send events on the server-side #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Manouchehri
Copy link

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

@bjesus
Copy link
Member

bjesus commented Apr 25, 2023

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
Copy link
Author

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
Copy link
Author

@bjesus The code has been reformatted as requested.

@bjesus
Copy link
Member

bjesus commented May 1, 2023

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
Copy link
Author

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 2b89361 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
Copy link
Member

bjesus commented May 3, 2023

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
Copy link
Author

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
Copy link
Member

bjesus commented May 16, 2023

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
Copy link
Author

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
Copy link
Author

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. =)

omarmosid added a commit that referenced this pull request Jul 24, 2023
@kuba-orlik
Copy link
Contributor

kuba-orlik commented Sep 1, 2023

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
Copy link

@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
Copy link
Author

@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.

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

Successfully merging this pull request may close these issues.

4 participants