Connect _hsenc with contact ID

ABorg
Member

Hi,

I've been looking at solutions to grab the _hsenc value with GTM, send it to our datawarehouse and then connect it with the Contact ID (or Record ID?) that I get from Hubspot

 

However, I am not sure how to decipher the _hsenc value and then connect it to the right contact back end. Any suggestions? 

 

Kindly

Andreas

6 Replies 6
mgraham60
Member

Some progress that I wanted to share with the community.

The plain text URL with _hsenc is stored in contacts -> properties -> hs_analytics_last_url.

However, this is not always populated - my guess is it appears in about 50% of contacts who have clicked through.

Here is code for API v1, which works with the new ACCESS-TOKEN. Not tried with v3 yet.

 

import requests
headers = { "Authorization": "Bearer <YOUR-ACCESS-TOKEN>" }
url= 'https://api.hubapi.com/contacts/v1/contact/email/' + user_email + '/profile'
response = requests.get(url, headers=headers)
print(response.json()["properties"]["hs_analytics_last_url"])

 

This is a lot of effort to avoid hubspot's encoded click tracking URL.

Are there plans to address this?

I cannot believe I am the only one whose click-thru rates are impacted by hubspotlinks.

cpanti
Participant

Hi @ABorg. Did you managed to solve it?
Thank you.

Catalin

0 Upvotes
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Hello @ABorg 

The hsenc value is a hashed value that is used to uniquely identify a contact in HubSpot. It is generated by HubSpot and is not something that you can decipher yourself. However, you can use the hsenc value to connect to the right contact back end by using the HubSpot API.

Here are the steps on how to connect the _hsenc value with the contact ID

Create a HubSpot API key.
Use the HubSpot API to get the contact ID for the _hsenc value.
Store the contact ID in your data warehouse.
Here is an example of how to use the HubSpot API to get the contact ID for the _hsenc value

import requests

def get_contact_id(hsenc):
    url = "https://api.hubspot.com/contacts/v1/contact/by-hsenc/" + hsenc
    headers = {
        "Authorization": "Bearer YOUR_API_KEY"
    }
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        return response.json()["id"]
    else:
        return None

contact_id = get_contact_id("YOUR_HSENC_VALUE")


Once you have the contact ID, you can store it in your data warehouse. You can then use the contact ID to query your data warehouse for information about the contact.

Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
mgraham60
Member

Is there a way to search for _hsenc in the v3 api?

As YOUR_API_KEY has been deprecated, headers requires YOUR_ACCESS_TOKEN instead, which returns 404 with the older v1 API above.

I'm trying to link the _hsenc in Google Analytics to the _hsenc in a sent email (which I assume Hubspot stores somewhere).

The reason for this is I dont want to use hubspotlinks for tracking clickthrus as my audience wont click through when they see the encoded URL.

 

VMüller4
Participant

Hi @himanshurauthan , 
I followed your tutorial but I only get "None" values as reply. I contacted HS Support who told me that decoding the `hsenc` value is not possible. I urgently need to decode it to get the real contact_id, do you have any idea how to solve this?
Thanks,
Verena

0 Upvotes
cpanti
Participant

Hi @himanshurauthan.

I get a 404 Not Found on the url you mentioned.

Also I couldn't find any reference to by-hsenc into the documentation.

I can search by utk, but I'm not able to search by hsenc.
https://legacydocs.hubspot.com/docs/methods/contacts/get_contact_by_utk

Please advise.

Catalin

0 Upvotes