1

Firstly, while stackOverflow has helped me many times before, this is my first ever posted question. Thus, please be gentle (I'm still new to coding) and provide any suggestions if I am doing something wrong in regards to stackOverflow protocol :-)

My issue:

I am trying to w3c validate my code using the Nu Html Checker and I keep running into a similar issue in many pages and can't yet find a solution.

It has to do with issues with my Google Analytics Event Tracking using onclick.

Here are the repeated error messages I am getting from the validator:

  • Error: No space between attributes.
  • Warning: Attribute ; is not serializable as XML 1.0.
  • Warning: Attribute false; is not serializable as XML 1.0.
  • Error: Attribute ; not allowed on element a at this point.
  • Error: Attribute return not allowed on element a at this point.
  • Error: Attribute false; not allowed on element a at this point.

ALL these errors are occurring on Line 174.

Here is the Line 174 code I am using:

<h2><b><a href="free.html" onclick="ga('send','event','outbound','click', 'foundations')" target="_self"; return false;>Click Here to Access</a></b> for <b>Free</b>.</h2>

Now, I know in theory that I could probably solve this by removing ; return false; but I'm concerned this will kill my Event Tracking in Google Analytics (as as far as I am aware you need return false; to trick link click events, especially when they take you to an external site (which some other pages with similar errors do).

So:

  • How do I solve these w3c Validation errors,
  • While still tracking Google Analytic Events?

Thanks for any and all help, Axel

5
  • what kind of doctype are you using?
    – lucas
    Commented Jan 11, 2016 at 10:12
  • I think I have found a simple solution (which also makes me look a little stupid): I think I CAN just remove ; return false; and everything still works as planned. Valid HTML, Event was tracked & link worked fine. Thanks @lucas for your response, you put me at ease after my first question! Just a bit silly that I finally get the courage to post a question (after spending hours trying to solve this), and it gets solved within 30-mins by doing the thing that I originally said couldn't be done :-/ Thanks all!
    – Axel
    Commented Jan 11, 2016 at 10:36
  • The better solution would be not to use inline javascript code at all, but attach a click event handler to the links via a javascript function (no problems with the doctype plus if you need to change anything in your tracking you can change it for all your links at once). Commented Jan 11, 2016 at 11:07
  • Thanks @EikePierstorff, that sounds like it would be preferable. I don't know 100% how to do it yet (I'm still at the early stages of teaching myself), but I'm sure it's nothing that a Google Search and a tutorial or two couldn't handle. I'll try it :-) Thanks again
    – Axel
    Commented Jan 11, 2016 at 11:24
  • W3Schools came up as Search Result #1 "click event handler to the links via a javascript function". Thanks again.
    – Axel
    Commented Jan 11, 2016 at 11:27

1 Answer 1

0

maybe more like so, without the semicolons between attributes and the return false inside the onclick

<h2><b><a href="free.html" onclick="ga('send','event','outbound','click', 'foundations'); return false" target="_self">Click Here to Access</a></b> for <b>Free</b>.</h2>
2
  • Thanks for the answer, @lucas. This two-thirds worked ...actually you solved the questions I asked (1) Validation was perfect (2) Events were tracked. But there was just one problem: the link didn't take me through to the free.html page, it kind of acted like a dead link.
    – Axel
    Commented Jan 11, 2016 at 10:26
  • It would appear that your return false is blocking the redirect to the free.html page. You could alternatively use a callback function as outlined here: support.google.com/analytics/answer/1136920?hl=en
    – nyuen
    Commented Jan 11, 2016 at 18:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.