javascript - How to send notification when user clicks ad? -


I am developing a system that shows ads on mobile devices. Our customers are allowed to use their custom HTML code for their advertisement when a user clicks on this ad and we want to notify them. I can wrap the user's code with some of my code for example:

  & lt; Div id = "my-code" onclick = "myfunction ()" & gt; & Lt ;! - User code - & gt; & Lt; A href = "http://whatever.com/" & gt; Click me! & Lt; / A & gt; & Lt; Button onclick = "someCode ()" /> & Lt; / Div & gt;  

As you can see, users can use Javascript inside their ads when the ad is clicked and I want to make an external server notification, Do not want to change the behavior of I have tried many ways and failed to do one task:

  1. I am unable to use AJAX because Ajax is limited to the domain of the page only (ad on external page Are shown and we can not connect to the server). An alternative approach tracking pixel is used, but:
  2. A tracking pixel needs some time to load. If the user has and gt; tag, then the pixel tracker added by myFunction () will not be loaded before switching to a new page. I can stop the promotion of the event, but:
  3. The ad must also get this click I tried to stop the promotion of the event in Javascript, load the pixel tracker, and then trigger the event again. Does not work - & lt; A & gt; Tags are not clicked in such a way - a click event triggered by Javascript is present at the JavaScript level only.

Any suggestions would be appreciated.

Maybe you can do something like

  & lt; Body & gt; & Lt; Div id = "linkContainer" & gt; & Lt; One goal = "_ blank" href = "http://www.icrc.org/eng/" & gt; Link & lt; / A & gt; & Lt; / Div & gt; & Lt; Script type = "application / javascript" & gt; $ (Document) .ready (function () {function beforeLeave () {alert ("outa here!"); // function to execute agax-call server} $ ('# linkcontainer & gt; a') ('Click', function () {beforeLeave ();});}); & Lt; / Script & gt; & Lt; / Body & gt;  

Comments