extended use of CSE HTML Validator for piwik users?

For technical support for all editions of CSE HTML Validator. Includes bug reports.

extended use of CSE HTML Validator for piwik users?

Postby nullptr » Wed Dec 26, 2012 6:02 am

Hello all,
I try to implement piwik in an existing webpage.
Piwik is a tool which monitors webtraffic. It is a free version of google
analytics. See http://de.piwik.org/.

The html code can be modified in two ways.
First, a JavaScript tag ist implemented in the html-header which tracks page views.

The second option is to additionally monitor user interactions. The piwick manual says, that I have to call
the JavScript function trackPageView() via onclick attribute. I.e. something like

<a href="#" onclick="javascript:piwikTracker.trackPageView('Menu/Freedom');">Freedom page</a>

So here comes HTML-Validator. I'd like to use HTML-Validater to alert me, whenever an <a> element
with a href= attribute has no onclick attribute linking to function trackPageView.

I wonder whether is can be done?
Any hint is very much appreciated
nullptr
Rank 0 - Newcomer
Rank 0 - Newcomer
 
Posts: 2
Joined: Wed Dec 26, 2012 2:31 am

Re: extended use of CSE HTML Validator for piwik users?

Postby Albert Wiersch » Thu Dec 27, 2012 1:24 pm

Hello,

Please try this. Note that this requires the professional or enterprise edition because it uses a 'user functions' file.

1. Create a 'user functions' file in a text editor and call it 'piwik.cfg' (or choose your own name).

2. Put this in the file:
Code: Select all
function onStartTag_a() {
 if hasAtt('href') {
  if hasAtt('onclick') {
   $tpv_ok=false;
   $onclickvalue=convertString(65536,getAttValue('onclick'));
   if beginsWithNoCase($onclickvalue,'javascript:') {
    if getStringStartIndex($onclickvalue,'trackPageView')>=0 {
     $tpv_ok=true;
    }
   }
   if !$tpv_ok {
    Message(1,MSG_ERROR,'This tag\'s "onclick" attribute does not call trackPageView().');
   }
  }
  else {
   Message(1,MSG_ERROR,'This tag has no "onclick" attribute with trackPageView().');
  }
 }
}


3. In CSE HTML Validator, goto Options->Validator Engine Options->Options and then the Validator Engine->Config File page. Set the 'user functions' file to the file you just created that contains the above code.

4. Be sure to reload the configuration so that the new code is loaded.

5. Let me know how it works. It should generate error messages for "a" tags that have "href" values but that 1) don't have an "onclick" attribute, or that 2) have an "onclick" attribute but it doesn't contain "trackPageView".
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX

Re: extended use of CSE HTML Validator for piwik users?

Postby nullptr » Thu Dec 27, 2012 1:54 pm

Hello Albert,
I am very thankful for your quick and effective help!
Works as desired - impressive.
Thanks a lot
nullptr
Rank 0 - Newcomer
Rank 0 - Newcomer
 
Posts: 2
Joined: Wed Dec 26, 2012 2:31 am

Re: extended use of CSE HTML Validator for piwik users?

Postby Albert Wiersch » Thu Dec 27, 2012 2:42 pm

nullptr wrote:Hello Albert,
I am very thankful for your quick and effective help!
Works as desired - impressive.
Thanks a lot


Great! :D

I'm glad I could help.
Image
Albert Wiersch
User avatar
Albert Wiersch
Site Admin
Site Admin
 
Posts: 2361
Joined: Sat Dec 11, 2004 10:23 am
Location: Near Dallas, TX


Return to CSE Tech Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron