Identify visitor


#1

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: (https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor)
var _hsq = window._hsq = window._hsq || [];
_hsq.push([“identify”,{
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 || [];
_hsq.push([“identify”,{
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.


#2

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


#3

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


#4

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?


#5

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?

Regards
Eirin


#6

@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.


#7

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?


#8

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


#9

@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?


#10

Hello,
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: ‘<%= current_user.email %>’ }]);
_hsq.push([‘trackEvent’,{ email: ‘<%= current_user.email %>’ }]);
_hsq.push([“trackPageView”, {email: ‘<%= current_user.email %>’}]);

I’m testing locally…

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

Thanks