JSFiddle - React, Tailwind, and code Playground

by Nicolas PUJOL

HTML

<script src="https://code.jquery.com/jquery-1.4.2.js"></script>
<div class="phone icon-phone">
    <h3>
     <a class="tel" href="tel:01702811774">01702811774</a>
  </h3>
</div>

JavaScript

/*
1. button on page with href of a phone number
2. page loads, stores number in a var
3. adds a pixel to the page (like before)
4. redirects user to the phone number (like if they clicked the original button)
*/

$(function() {
    var pixel = '//pixel.mathtag.com/event/js?mt_id=1113916&amp;mt_adid=178945&amp;v1=&amp;v2=&amp;v3=&amp;s1=click_to_call&amp;s2=&amp;s3=';
    var eventHandled = false;
    $('a.tel').click(function(e) {
        if (!eventHandled) {
            e.preventDefault();
            e.stopPropagation();
            eventHandled = true;
            var s = document.createElement("script");
            s.type = "text/javascript";
            s.src = pixel;
            $("head").append(s);
            setTimeout(function() {
                $('a.tel')[0].click();
            }, 1000);
        }
    });
});