APIs & Integrations

ym42324
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Portal id 5664924, website www.fauxwoodbeams.com. Hubspot script is loaded on the top of the page.

 

I am trying to solve a problem of most contacts and deals being attributed to “offline source”, which looks unrealistic and prevents us from having a marketing overview.

 

Most of our contacts are added via API. Customers are asked to provide their email address when they begin checkout. That email is then used to look up their contact id in Hubspot using API, or, if contact was not found, create a new contact, also via API. The id of the contact is then associated with a new deal, which is also created in Hubspot via API.

 

The problem we face is the following: because most contacts are created via API, they are always being attributed to “Offline source”, even though all of them visit the website prior to creation, and thus need to be attributed to other sources (PPC, organic search, etc.).

 

I spent a decent amount of time researching this and reading all sorts of threads and documentation. One thing I found was this article: https://www.izooto.com/blog/solved-offline-sources-problem-hubspot-fixed-attribution, which suggests the HS script should always be at the top. Even though I placed the script to the top, I added “async defer” attributes to it for the sake of increasing page loading speed. So now I removed it.

 

Second thing I came across is “Identify a visitor” feature described here: https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor

 

What I did was I added the following lines of code into the script that executes when customer clicks “Proceed to checkout” button:

 

var _hsq = window._hsq = window._hsq || [];

_hsq.push(["identify",{ email: memb_email }]);

 

Where “memb_email” is the variable that holds the email address customer typed in.

 

My question here is really: am I moving in the right direction? There won’t be immediate results, but I would like to know, if, from Hubspot tech’s point of view, these steps would help me solve the problem.

2 Accepted solutions
eduardoavargas
Solution
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

I solved a similar problem using the form api.
https://developers.hubspot.com/docs/methods/forms/forms_overview

I created a form on the hub and created the contact using this form via api.

View solution in original post

IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Hi, @ym42324.

 

Thanks for the detailed post!

 

To expand upon @eduardoavargas's post, if you are creating contacts with either the v3 CRM Contacts API or v1 Contacts API, the Original Source value "Offline Sources" is expected for new contacts, per this article.

 

While you can change the Original Source (hs_analytics_source) property value manually and via API, the only way to assign a value based on a contact's web activity is to associate the visitor's hubspotutk cookie with a contact record.

 

There are a few ways to do this. The three most relevant include:

  • The Forms API is by far the most popular method, since it allows you to create and update contacts with property values and cookies in a single request. We recommend this creation method for most web applications.
  • The Tracking Code API's identify method can also associate hubspotutk usertoken values with resulting contacts, but many customers I've worked with have found it more difficult to implement successfully.
  • The Timeline API is also an option to create contact records and associate them with usertoken values, but this API requires server-side requests and more infrastructure (i.e. a HubSpot developer app and OAuth authentication) than the two methods above.

Regarding your use of the identify method, it could help you set or retroactively update "Offline Sources" contacts with web activity-informed values if it is implemented correctly.

 

Are you triggering trackPageView after _hsq.push(["identify",{ email: memb_email }]);?

Isaac Takushi

Associate Certification Manager

View solution in original post

7 Replies 7
eduardoavargas
Solution
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

I solved a similar problem using the form api.
https://developers.hubspot.com/docs/methods/forms/forms_overview

I created a form on the hub and created the contact using this form via api.

ym42324
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Thank you, @eduardoavargas and @IsaacTakushi .

 

It looks like your suggestion for using forms API (instead of contacts API) did the trick for the most part. I created a form in Hubspot, and instead of creating contact via contacts API, I now submit email and hs_context (made of values of hutk, IP address, URL and pagename) to https://forms.hubspot.com/uploads/form/v2/5664924/[form-id]. This not only creates a contact, but also properly associates it with Hubspot cookie, and the traffic is now attibuted to PPC/Organic/campaign/etc. instead of "Offline Source".

 

The only issue I see is that some contacts/deals are associated with "Direct traffic". As a test, I tried erasing all cookies and user data in browser, then went to Google, typed "Faux Wood Beams", click on our link to go to website, and then placed an order. I did it a few times (erasing cookies and user data each time), but for some reason, all contacts created were associated to "Direct traffic", even though it was technically organic search.

0 Upvotes
eduardoavargas
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Hi @ym42324 
See that the hub will use several strategies to know that the user came from an organic origin, I believe that he will use a referer to detect.

I gave a quick analysis on your website and saw that there are some errors in the console and warnings that show that you entered the form 2 times. Take a look at this as it can work.

Another thing can sometimes take a while for the hub to compute the right source.

eduardoavargas
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

 

@ym42324 

I actually found the error.

You cannot delete the cookie, because when you move to the second page the reference is no longer google but your own website.

The hub uses the cookie to save the source.

0 Upvotes
IsaacTakushi
Solution
HubSpot Employee
HubSpot Employee

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Hi, @ym42324.

 

Thanks for the detailed post!

 

To expand upon @eduardoavargas's post, if you are creating contacts with either the v3 CRM Contacts API or v1 Contacts API, the Original Source value "Offline Sources" is expected for new contacts, per this article.

 

While you can change the Original Source (hs_analytics_source) property value manually and via API, the only way to assign a value based on a contact's web activity is to associate the visitor's hubspotutk cookie with a contact record.

 

There are a few ways to do this. The three most relevant include:

  • The Forms API is by far the most popular method, since it allows you to create and update contacts with property values and cookies in a single request. We recommend this creation method for most web applications.
  • The Tracking Code API's identify method can also associate hubspotutk usertoken values with resulting contacts, but many customers I've worked with have found it more difficult to implement successfully.
  • The Timeline API is also an option to create contact records and associate them with usertoken values, but this API requires server-side requests and more infrastructure (i.e. a HubSpot developer app and OAuth authentication) than the two methods above.

Regarding your use of the identify method, it could help you set or retroactively update "Offline Sources" contacts with web activity-informed values if it is implemented correctly.

 

Are you triggering trackPageView after _hsq.push(["identify",{ email: memb_email }]);?

Isaac Takushi

Associate Certification Manager
AlbaICC
Participant | Elite Partner
Participant | Elite Partner

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

Hello, Isaac:

We want to implement this for one of our clients and since this solution is from nearly 3 years ago we were wondering if this is still the best one?

Thanks in advance

ym42324
Participant

Properly identify source of contacts added via API (currently most attributed to “offline source”)

SOLVE

By the way, using Identify a visitor also works, but it has limitations. Most importantly, _hsq.push(["identify",{ email: 'name@example.com' }]); needs to be called before the contact is created, and some delay needs to be given for it to take effect, meaning it cannot be used in the same sequence of script runs. I tried doing it this way:

 

1) When customer clicks "Proceed to checkout", a JS even calls _hsq.push() and then posts email to checkout.php

2) checkout.php accepts email, creates deal in Hubspot, looks up contact id via Hubspot contacts API (using email from step #1 and assigns this contact id to new deal.

 

However, by the time checkout.php was executing, the contact was not yet in Hubspot, so it could not be looked up and associated to a deal. But when sufficient time was given (e. g. call _hsq.push(["identify",{ email: 'name@example.com' }]); on one page, and then look up that contact by email on another page in a separate event), it worked as well.

0 Upvotes