window.addEventListener(\"message\", function(event) {\n if (event.data.type === 'hsFormCallback') {\n if (event.data.eventName === 'onFormSubmit') {\n console.log(event.data);\n var formData = event.data.data;\n var formObj = formData.reduce(function(acc, curr) {\n acc[curr.name] = curr.value;\n return acc;\n }, {});\n window.dataLayer.push({\n 'event': 'hubspot-advanced-matching',\n 'form_id': event.data.id,\n 'email': formObj.email,\n 'phone': formObj.phone,\n 'first_name': formObj.firstname,\n 'last_name': formObj.lastname\n });\n } else if (event.data.eventName === 'onFormSubmitted') {\n window.dataLayer.push({\n 'event': 'hubspot-form-success',\n 'form_id': event.data.id\n });\n }\n }\n});<\/code><\/pre>\n\n\n\nSegment Identify events<\/h3>\n\n\n\n
Another great use case is the often-overlooked integration of Hubspot with Segment.<\/p>\n\n\n\n
In many clients that I’ve audited their accounts, I’ve come across a one-way data integration between Hubspot and Segment. This meant that only Segment was pushing data into Hubspot. It usually happens on a Segment Identify event that will trigger the equivalent Hubspot event. The most common scenario is an app login or sign-up form that triggers Segment which in turn triggers Hubspot.<\/p>\n\n\n\n
But many sites also have Hubspot forms for Demo Requests or gated content that don’t communicate with Segment.<\/p>\n\n\n\n
Since the data is readily available, we can easily trigger it to Segment as well.<\/p>\n\n\n\n
In this case, we can use the event listener to trigger the Segment Identify call directly (or via Google Tag Manager).<\/p>\n\n\n\n
window.addEventListener(\"message\", function(event) {\n if (event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {\n console.log(event.data);\n formData = event.data.data;\n const formObj = formData.reduce((acc, curr) => {\n acc[curr.name] = curr.value;\n return acc;\n }, {});\n analytics.identify(, {\n email: formObj.email,\n phone: formObj.phone,\n first_name: formObj.firstname,\n last_name: formObj.lastname\n });\n }\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"In a previous post, I described how to track Hubspot forms using Google Tag Manager for reporting conversions in various analytics and ad platforms. In this post, I’ll try to break down some advanced tracking concepts for which you can use your Hubpost form tracking. The Hubspot form listener The most robust way of tracking […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,42,134],"tags":[200],"class_list":["post-5505","post","type-post","status-publish","format-standard","hentry","category-facebook","category-google-ads","category-hubspot","category-segment","tag-forms"],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/5505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=5505"}],"version-history":[{"count":4,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/5505\/revisions"}],"predecessor-version":[{"id":5856,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/5505\/revisions\/5856"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=5505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=5505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=5505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}