- Priority: 0
- Status: Closed
- Theme: Alysum
-
Assigned To:
Fred
- Private: No
- Open Date: 25.05.22, 14:36
- Opened by: Sea tech and fun europe Danielle Martin
- 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.
Comments
AMP doesn’t allows any third party JS code
Find all information about development for AMP here https://amp.dev/documentation/guides-and-tutorials/
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.
See an example in the documentation FAQ#16 https://alysum5.promokit.eu/promokit/documentation/#faq The important thing is to add {literal} tag