APIs & Integrations

_patrick
Member

Associate Contact Creation with hubspotutk cookie for traffic sources

Our main website has hubspot tracking setup, and hubspotutk cookies are properly created when visiting that site. When a potential customer clicks on a link to to create a new account through our software (different site), I pass the hubspotutk cookie through the link to the other site. In the backend we use this cookie in the POST request to hubspot for our form. The form information appears to fill in just fine, but the hubspotutk doesn't seem to be properly associated since we always get X was created from Direct Traffic from No URL .

I have read varying ways to supply this depending on the situation (hs_context/context). I believe the latter is correct, but I've tried them both with no success.

The data is sent in the following format:

{
'email': ;self.email,
'context': {
'hutk': self.hubspotutk,
'pageUri': 'http://www.sample.com',
'ipAddress': '192.168.0.1',
'pageName': 'Sample',
},
'firstname': self.firstname,
'lastname': self.lastname,
'company': self.company,
'lifecyclestage': self.lifecyclestage,
'how_did_you_hear_about_us_':
self.how_did_you_hear_about_us_,
'key_contact': self.key_contact
}

0 Upvotes
7 Replies 7
_patrick
Member

Associate Contact Creation with hubspotutk cookie for traffic sources

Hi @Isaac_Takushi,

I've since upgraded to the v3 api and have had success creating contacts, companies, and linking the two. However, I am experiencing some inconsistency with this process.

The general approach is:

  1. Create a contact through form submission:
    'https://api.hsforms.com/submissions/v3/integration/submit/{portal_id}/{form_guid}'
  2. Verify the contact by id using a separate request:
    /contacts/v1/contact/utk/{utk}/profile?hapikey={hapikey}
  3. Create a company:
    /companies/v2/companies?hapikey={hapikey}
  4. Associate the company and contact:
    '/companies/v2/companies/{companyID}/contacts/{contactID}?hapikey={hapikey}

I'm experiencing issues in 2 places:

  1. When I verify a contact (step 2), sometimes the request fails to verify, and although the response indicates the contact could not be found, it is there when I check on Hubspot.
  2. When I try to associate a contact with the new company (step 4), sometimes the request fails with a 404. Both company and contact exist on Hubspot when I check.

Both of these issues only occur sometimes, so I'm thinking that I'm verifying the contact before it's fully set up in Hubspot or trying to associate the contact with the company before both are fully set up.

Is this a common issue? Do you just tell customers to wait between dependent steps?

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Associate Contact Creation with hubspotutk cookie for traffic sources

Hey, @_patrick.

That contact has since been deleted. Would you mind sharing another one? I'd like to check the form submission JSON to verify whether the hutk was passed in the correct object.

Regarding your questions:

  • If you don't need tracking data from app.shoobx.com, then I suppose you don't need to install the 3411792 tracking code. As long as the hutk value is passed correctly, the new contact's Original Source value will reflect how they first reached www.shoobx.com but the form submission won't properly reflect the page it was submitted on and the contact won't show any browsing activity on app.shoobx.com.
  • With your second question, I think you're getting at the fact that your production account's tracking code is already on www.shoobx.com so you can't reliably test the developer account's tracking code there, right? I don't know of any way to generate a hubsoptutk cookie token value without installing first the desired tracking code on a page, so perhaps you could place the 4525761 tracking code on app.shoobx.com just to test whether you can get any tracking data into HubSpot?

Isaac Takushi

Associate Certification Manager
0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Associate Contact Creation with hubspotutk cookie for traffic sources

Hey, @_patrick.

Thanks for that information! A few things jump out to me.

  • The Hub ID you provided (4525761) is your developer test account while your production account is 3411792.
  • The tracking code for account 3411792 is installed and firing on https://www.shoobx.com but not on https://app.shoobx.com.
  • The tracking code for account 4525761 is missing on both https://www.shoobx.com and https://app.shoobx.com.
  • You are creating contacts in the developer test account 4525761 but the tracking code on your site is tied to your production account, 3411792. As a result, no contact created in the test account will be properly tracked. Even though the hutk token value is present, it shouldn't mean anything to account 4525761.
  • This contact's form submission data, visible here, shows that you're trying to pass hutk as a property value. On the back end, however, I see that it was not passed properly in the meta data array. This is all that shows:
"meta-data" : [
{
"name" : "requestIpAddress",
"value" : "65.96.163.45"
},
{
"name" : "apiContextMissing",
"value" : "ipAddressNotSupplied"
},
{
"name" : "endpointType",
"value" : "LEGACY_UPLOAD"
},
{
"name" : "serverRegion",
"value" : "us-east-1"
}
]

If you're using the v2 Forms API endpoint, make sure that the hs_context parameter is JSON-formatted and URL encoded. For example:

&email=formsub@hubspot.com&newcustomproperty=testing&hs_context=%7B%22hutk%22%3A%2260c2ccdfe4892f0fa0593940b12c11aa%22%2C%22ipAddress%22%3A%22192.168.1.12%22%2C%22pageUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fcontact%2F%22%2C%22pageName%22%3A%22Contact%2BUs%22%2C%22redirectUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fthank-you%2F%22%7D

Isaac Takushi

Associate Certification Manager
0 Upvotes
_patrick
Member

Associate Contact Creation with hubspotutk cookie for traffic sources

Thanks for this info @Isaac_Takushi. I just recently assumed all the Hubspot things so am still figuring out the existing infrastructure put in place.

I had just realized this issue with hubspot IDs and have created an account using the non-developer Hub ID: https://app.hubspot.com/contacts/3411792/contact/2315001/?interaction=note

It still doesn't have the proper tracking, but as you said I probably need to fix how the utk is being passed.

I have a few questions though:

  • I don't need 3411792 to be on https://app.shoobx.com if all the hubspot requests are made using the forms API, right? If I first associate the contact creation with the utk and then use the email from there on out it should be ok?

  • Is there a way I can easily generate hubspotutk cookie value to test the account creation using our developer Hubspot ID?

0 Upvotes
IsaacTakushi
HubSpot Employee
HubSpot Employee

Associate Contact Creation with hubspotutk cookie for traffic sources

Hey, @_patrick!

I suspect we may be dealing with some cross-domain cookie shenanigans. Happy to help investigate. Would you mind clarifying the following?

  1. What is your Hub ID?
  2. What is your main website's domain?
  3. Exactly what action(s) do they take to reach your account site?
  4. What is your account site's domain?
  5. What do you mean by "I pass the hubspotutk cookie through the link to the other site." Which direction is the cookie going and how are you passing it? Are you using the __hsfp , __hssc , and __hstc parameters described here?
  6. Are your visitors at any point moving from a secure HTTPS domain to an insecure HTTP domain?
  7. Are you using the v3 Forms API endpoint? If so, you will indeed use JSON and the context object (as opposed to hs_context, which is used for the v2 endpoint).
  8. Can you provide links to some example contacts showing this behavior?

Isaac Takushi

Associate Certification Manager
0 Upvotes
_patrick
Member

Associate Contact Creation with hubspotutk cookie for traffic sources

Thanks for the reply, @Isaac_Takushi

I hope this answers all those questions effectively:

  1. 4525761
  2. https://www.shoobx.com/
  3. There are several buttons that will redirect to the application where they can make an account.
  4. https://app.shoobx.com/
  5. On the main website, we provide the hubspot cookie in the url redirect like this: http://app.shoobx.com/start?hubspotutk=VALUE
  6. It's all over HTTPS
  7. I am using v2, although I did try hs_context before (also can you pass just the cookie itself in there?).
  8. https://app.hubspot.com/contacts/4525761/contact/9751/?interaction=note
0 Upvotes
_patrick
Member

Associate Contact Creation with hubspotutk cookie for traffic sources

Here's a contact I made today https://app.hubspot.com/contacts/4525761/contact/9801/?interaction=note

When making this contact, I changed the data in my first post so that context is now hs_context.

0 Upvotes