• Closed by: Anonymous Submitter
  • Closed on:
  • Reason: Not a bug

Ticket #23381 - Add javascript

Hello,
we would like to add a javascript code on a link. <a id=”xxx” ….>
And do an action on onclick(elementgetbyID).
It works in normal mode (computer) but not in AMP.
I added the javascript code just before the end of the </body> tag
In the code: mobile/layouts/layout-main.tpl
Thanks for your help.

Attachments:

javascript.JPG (100 KiB)
javascript2.JPG (46.5 KiB)
javascript3.JPG (63.8 KiB)

Comments

Fred 26 May 2022, 12:19

AMP doesn’t allows any third party JS code
Find all information about development for AMP here https://amp.dev/documentation/guides-and-tutorials/

Sea tech and fun europe Danielle Martin 27 May 2022, 09:52

Hello,
Could you please help implement this code?
<script type=”text/javascript”>
document.getElementById(”mon_id”).onclick = function() { ga(’send’,’event’,’Test ajout panier’); }
</script>
The image is on the home page (AMP) and the image is the first (banner) ID=”mon_id”.
If on the click of this image ca could play the function ga(…..)?

I added the code: <script async custom-element=”amp-script” src=”https://cdn.ampproject.org/v0/amp-script-0.1.js“></script> in the header.

Thanks for your help.

Fred 27 May 2022, 11:28

See an example in the documentation FAQ#16 https://alysum5.promokit.eu/promokit/documentation/#faq The important thing is to add {literal} tag