onclick return two functions (Tracking)


I'm trying to trigger two functions on the onclick event. They are used for tracking link from website. One is for GoogletagManager, the other one is for AdForm tracking.

I get error that the function is not defined. Any solutions to make this work?

<a href="https://www.example.com" target="_blank" onclick="myFunction();">Link</a>

  <script type="text/javascript">

  function myFunction(){
      secondone();
      firstone();
  }
  function firstone() {
      return console.log('first');
      return gtag_report_conversion1('http://www.example.com');
  }
  function secondone() {
      return console.log('second');
      return window.adf&&adf.ClickTrack ( this,{123456},'Page Name',{});
  }

  </script>
  <script>
function gtag_report_conversion1(url) {
  var callback = function () {
    if (typeof(url) != 'undefined') {
      window.location = url;
    }
  };
  gtag('event', 'conversion', {
      'send_to': 'AW-465465465465465',
      'event_callback': callback
  });
  return false;
}
</script>
<script type="text/javascript">
      window._adftrack = Array.isArray(window._adftrack) ? window._adftrack : (window._adftrack ? [window._adftrack] : []);
      window._adftrack.push({
          pm: 123456,
          divider: encodeURIComponent('|'),
          pagename: encodeURIComponent('Page Name')
      });
      (function () { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://track.adform.net/serving/scripts/trackpoint/async/'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();

  </script>
- - Source

Answers

answered 5 mon ago NBlaine #1

After reading your edit - try moving all of the functions to the same <script></script> tag :)

comments powered by Disqus