I have created a membership site using Ruby on Rails and when users sign up I create the contact in hubspot. I don't get any user tracking and wondered what i was missing?
As its not a hubspot form on signup do I need to write some custom javascript?
I ran some tests on my own site and confirmed that the identifywill update a contact record's web history and Original Source from "Offline Sources," similar to what is described in this article. We're looking to be in good shape!
That said, I'm noticing a few things with your code. The identify method's documentation defines the email value in single quotes without a semicolon at the end. For example:
Just keep in mind that — as this documentation notes — calling trackPageView "manually before or during the initial page load could lead to duplicate views being tracked." I don't know where exactly the code above lies on your site, so it may well be appropriate to trigger it manually.
I would not recommend calling identify on each page. When you identify a visitor and trackPageView runs (either manually or through the tracking code), HubSpot associates the cookie and page views with a contact's user token. The tracking code then remembers the cookie going forward, so you don't need to identify the visitor again unless they have a new cookie. Thus, I think your decision to include the identify function in your log in flow is best.
<% if user_signed_in? %>
<script type="text/javascript">
$(document).ready( function() {
var _hsq = window._hsq = window._hsq || [];
_hsq.push(["identify",{
email: <%= current_user.email %>
}]);
_hsq.push(['setPath', window.location.pathname]);
// Track the page view for the new page
_hsq.push(['trackPageView']);
});
</script>
<% else %>
<script type="text/javascript">
$(document).ready( function() {
var _hsq = window._hsq = window._hsq || [];
_hsq.push(['setPath', window.location.pathname]);
// Track the page view for the new page
_hsq.push(['trackPageView']);
});
</script>
<% end %>
I check to see if the user is logged in. If so we know the users email, set the identity and track page views. If user is not logged in we don't set the identity and hope they have the cookie and track page views. Would setting identify on every page cause a problem?
All contacts created via the Contacts API will have the Original Source value "Offline Sources" and no page views at first. You can pass page view and source tracking information later with the identify method — assuming the contact is on the same browser and hasn't cleared their cookies — and this should update the Original Source property value.
While the flow above will work, if capturing page views and the correct Original Source value from the get-go is a priority for you, then I still recommend using the Forms API to pass the hutk cookie token value with the initial submission. I recognize that this would require more work up front, however.
Happy to help. Are you creating contacts with the Contacts API?
If so, the Contacts API is better suited for offline conversions and can't pass browsing information. If your leads are converting online, it's best to use either the Forms API or the tracking code's identify method.
If you are using the Forms API, are you scraping and passing the HubSpot utk cookie token value in the context object? If you believe you are and you're still not seeing tracking information, share links to a few example contacts and I'll take a look!
I'm creating the contacts via the Contacts API as I'm using the hubspot-ruby gem in my rails application.
I have tried to make use of the identify method, by checking to see if the user has signed into the application if so I then call the identify method as I will know the users email at that point? Does that sound ok?