title: phone numbers for mobile devices with tracking code
body: <p>The users of a TYPO3 can add a phone number (as text) like so <code>+49(0)1234/567890</code>. This leads to the following HTML output.</p>
  
  <pre><code>&lt;p class="bodytext"&gt;Some Text&lt;br&gt;
      Telephone: +49(0)1234/567890&lt;br&gt;
      Fax: +49(0)1234/56789
  &lt;/p&gt;
  </code></pre>
  
  <p>Now I should reformat the phone numbers for the mobile version like <code>tel:0049123467890</code>. But I have to do more. I have to add a tracking code on to this link. E.g.:</p>
  
  <pre><code>&lt;a href="tel:0049123467890" onclick="javascript:_gaq.push(['_trackEvent', 'Mobile', 'URL', 'Call']);" target="_blank" title="call me"&gt;0049123467890&lt;/a&gt;
  </code></pre>
  
  <p>How should I do that?</p>
  
  <p>First I thought about a Javascript/jQuery solution like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      /* &lt;![CDATA[ */
      $(function(){
          $("span, p").each(function() {
              var phonelink = '&lt;a href="tel:0049123467890" onclick="' + "javascript:_gaq.push(['_trackEvent', 'Mobile', '" + document.URL + "', 'call']);" + '" target="_blank" title="call me"&gt;+49(0)1234/567890&lt;/a&gt;';
              var text = $(this).text();
              text = text.replace("+49(0)1234/567890", phonelink);
              $(this).text(text);
          });
      });
      /* ]]&gt; */
  &lt;/script&gt;
  </code></pre>
  
  <p>This doesn't do what I expect. If I do that the whole formatting is destroyed. Am I doing something wrong here?</p>
  
  <p>In general I would look for a cleaner solution. That means that the content should be adapted on the server side. So the content of TYPO3 should be replaced before the website is delivered to the mobile device. Generally, the phone number should not change and it must be assured that the phone number is always in the same format. But here I don't know how that can be implemented.</p>
  
  <p>Or am I completely wrong and there is a better solution?</p>