-
Notifications
You must be signed in to change notification settings - Fork 2
Hubspot example #25
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
Draft
devkiran
wants to merge
4
commits into
main
Choose a base branch
from
hubspot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Hubspot example #25
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Contact Us</title> | ||
</head> | ||
<body> | ||
<h1>Contact us</h1> | ||
<!-- Load HubSpot forms library --> | ||
<script src="https://js.hsforms.net/forms/embed/47839131.js" defer></script> | ||
|
||
<!-- Load Dub analytics script --> | ||
<script | ||
src="https://www.dubcdn.com/analytics/script.js" | ||
defer | ||
data-domains='{"refer":"acme.link"}' | ||
></script> | ||
|
||
<div | ||
class="hs-form-frame" | ||
data-region="na1" | ||
data-form-id="07b7409d-cf6b-4d9f-9926-76d55b591e88" | ||
data-portal-id="47839131" | ||
></div> | ||
|
||
<script> | ||
// Read cookie value | ||
function getCookie(name) { | ||
const value = `; ${document.cookie}`; | ||
const parts = value.split(`; ${name}=`); | ||
|
||
if (parts.length === 2) { | ||
return parts.pop().split(";").shift(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
// Listen for the form ready event | ||
window.addEventListener("hs-form-event:on-ready", (event) => { | ||
const clickId = getCookie("dub_id"); | ||
|
||
if (!clickId) { | ||
console.debug("clickId not found. Skipping lead tracking."); | ||
return; | ||
} | ||
|
||
// Add the clickId to the form | ||
// Note: Make sure you have a hidden field with connected property "dub_id" | ||
HubSpotFormsV4.getForms()[0].setFieldValue("0-1/dub_id", clickId); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Contact Us</title> | ||
</head> | ||
<body> | ||
<h1>Contact us</h1> | ||
|
||
<!-- Load Dub analytics script --> | ||
<script> | ||
!(function (c, n) { | ||
c[n] = | ||
c[n] || | ||
function () { | ||
(c[n].q = c[n].q || []).push(arguments); | ||
}; | ||
["trackClick", "trackLead", "trackSale"].forEach( | ||
(t) => (c[n][t] = (...a) => c[n](t, ...a)) | ||
); | ||
var s = document.createElement("script"); | ||
s.defer = 1; | ||
s.src = "https://dubcdn.com/analytics/script.conversion-tracking.js"; | ||
s.setAttribute( | ||
"data-publishable-key", | ||
"dub_pk_tLnpzXvJAEik0UtzuzdmMJSn" | ||
); // Replace with your publishable key | ||
s.setAttribute("data-domains", '{"refer":"dub.sh"}'); | ||
s.setAttribute("data-api-host", "http://localhost:8888/api"); | ||
document.head.appendChild(s); | ||
})(window, "dubAnalytics"); | ||
</script> | ||
|
||
<div | ||
class="meetings-iframe-container" | ||
data-src="https://meetings.hubspot.com/kiran61?embed=true" | ||
></div> | ||
|
||
<!-- Load Meetings Embed Script --> | ||
<script | ||
type="text/javascript" | ||
src="https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js" | ||
></script> | ||
|
||
<script> | ||
// Read cookie value | ||
function getCookie(name) { | ||
const value = `; ${document.cookie}`; | ||
const parts = value.split(`; ${name}=`); | ||
|
||
if (parts.length === 2) { | ||
return parts.pop().split(";").shift(); | ||
} | ||
|
||
return null; | ||
} | ||
devkiran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Listen for the message event | ||
window.addEventListener("message", function (event) { | ||
// Check if the message is from the scheduling widget | ||
if (event.origin === "https://meetings.hubspot.com") { | ||
const clickId = getCookie("dub_id"); | ||
|
||
if (!clickId) { | ||
console.debug("clickId not found. Skipping lead tracking."); | ||
return; | ||
} | ||
|
||
// Get the data from the event | ||
const data = event.data; | ||
|
||
if (data.meetingBookSucceeded) { | ||
// Get the scheduled contact | ||
const contact = | ||
data.meetingsPayload.bookingResponse.postResponse.contact; | ||
|
||
if (!contact) { | ||
console.debug("contact not found. Skipping lead tracking."); | ||
return; | ||
} | ||
|
||
console.debug("contact found", contact); | ||
|
||
// Track the lead with the scheduled contact | ||
const customerName = [contact.firstName, contact.lastName] | ||
.filter(Boolean) | ||
.join(" "); | ||
|
||
dubAnalytics.trackLead({ | ||
clickId, | ||
mode: "deferred", | ||
eventName: "Meeting scheduled", | ||
customerExternalId: contact.email, | ||
customerName: customerName, | ||
customerEmail: contact.email, | ||
}); | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The analytics script is configured to use a localhost development URL that will fail in production.
View Details
Analysis
Hard-coded localhost API URL breaks analytics in production deployment
What fails: Dub analytics script in
conversions/hubspot/meeting.html
uses hard-codeddata-api-host="http://localhost:8888/api"
that fails outside development environmentHow to reproduce:
Result: Analytics tracking requests fail, no conversion data collected. Browser console shows network errors attempting to reach localhost:8888.
Expected: Should use default production API endpoint
https://api.dub.co
like other examples in the repository per Dub Analytics documentation