Identify visitor


I’m trying to identify a user who logs in to our webpage (we use Craft CMS) and report this to hubspot to begin tracking the user.

I have added a javascript function which runs when a user logs in:

Fetched from: (
var _hsq = window._hsq = window._hsq || [];
email: getParameterByName(“email”)

And further on it says: The data will only be passed when tracking a pageview or an event (with either the trackPageViewor trackEvent functions).

So I tried to create a custom event, below is the complete code:
Useremail is logged in user, which exists in hubspot and Craft):

var _hsq = _hsq || [];
email: useremail,

                                            // Update to 'true' if you want to track event on every page view
                                                            if (true) {
                                                                                            _hsq.push(["trackEvent", {
                                                                                                                            id: "000002638763",
                                                                                                                            email: useremail,

Can you tell me if what I’m trying to do is correct, to identify logged in user and track this user in our webpage?

Nothing is logged on the user, but the custom event has a completion registered on it (but no contacts).

Also I’m testing locally where localhost is given a domain name and I can see visited urls in my hubspot test account (completions), but no contact activity.

Thank you.


@eirin Can you log the email and prove that the value is there? Did you use the getParameterByName function as well?


Yes, I did debug and saw that the correct email address was there.
I did not use the getParameterByName.


can you help me understand this line here?

//Update to 'true' if you want to track event on every page view
if (true) {

This would run every time no matter what so why is this wrapped in an if statement?


It’s just for test. I need to change it, but I thought I should see an event happening on the correct contact before I spent time on handling the logic for when it should happen. I also need to move the code because now it’s happening each time the page is loaded if the user is logged in. The code you’re referring to is fetched from hubspot page.
Could the problem be that I’m testing internally using a domain for localhost?



@eirin I don’t think testing it locally is the issue. It will run every time until you make a different condition in your if statement. since right not it will always result to true it will run every time.


Yes, It was just someone else in your organization mentioned that hubspot did not allow for localhost testing (as domain). But does the code look correct to you? Could it be something with the event I configured?


Can I add this code in my own html or must it be stored in the event in hubspot?


@eirin Do you know who you were talking to internally? I’m not aware of any issues testing locally to run the tracking code and fire off an event. Can you paste your current code in here again so I can see if it looks correct to me or not?


I have the same issue…
I try several _hsq.push and there is no activity logged in the user page on hubspot :
_hsq.push([“identify”,{ email: ‘<%= %>’ }]);
_hsq.push([‘trackEvent’,{ email: ‘<%= %>’ }]);
_hsq.push([“trackPageView”, {email: ‘<%= %>’}]);

I’m testing locally…

Is there a delay to have the activity information on the user page or should it be instant ?