So I am trying to create a custom event to track clicks but it doesn’t work. Please tell me what I am missing. My website is in hubspot so it already has the tracking code. Then I go to Reports -> Events click create new event, select custom event click javascript API and put this code there
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var _hsq = window._hsq = window._hsq || [];
_hsq.push(["identify",{
email: getParameterByName("email")
}]);
_hsq.push(["trackEvent", {
id: "000001105495"
}]);
_hsq.push(["trackClick", "h1", "000001105495"]);
Then I click save. So then I open my test page http://wireline-dev-2522899-2522899.hs-sites.com/teste and click on the h1 title >“Enter the on-page title” then I go to the events and nothing is tracked completions are 0 contacts are 0 customers are 0. What am I doing wrong here?
@hayk I got an event to register using the following code.
_hsq.push(["trackEvent", {
id: "000001411558",
value: "clicked the h1"
}]);
Are you wrapping your code in an OnClick event as well? You need to have something call the code on each click or else it will only fire once on page load.
Yes I do that, I tried with and without quotes. And when I do that with quotes I get this warning from v2.js v2.js:4 The specified value "'hayk@incredo.co'" is not a valid email address. But anyway I don’t get any event completions with and without quotes.
@hayk In the drop down when you make a new event you could chose the create a clickable event. That might be an easier way to create the functionality you are looking for.
Well my exact aim is not this I just want to figure out how the Javascript API works. So do you have any guesses what I am doing wrong there ?
EDIT: Is there anything else I need to do after creating the events? Like add them somewhere in the pages , or as far as I get it they added to the pages as soon as I create them, didn’t they?