cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a java script in the footer? Magento 2.X

SOLVED

How to add a java script in the footer? Magento 2.X

I'm having trouble when trying to put a java script on my footer.

 

I've just bought a marketing automation plataform and to integrate it with magento 2.x I need to put this script.

 

Anyone has done this before? Thank you in advance Smiley Happy

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to add a java script in the footer? Magento 2.X

Hi @andré_scaff 

 

I have put the javascript on shared path and flush the cache so while loading the website it alerts "Hi".

 

See attached screen shot for your reference:

sol11.png

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
alert("Hi");
});
</script>

 

This is the example which I put and got alert. Please try in this way, hope it will work for you as well.

 

if issue solved,Click Kudos & Accept as Solution

View solution in original post

6 REPLIES 6

Re: How to add a java script in the footer? Magento 2.X

Hi @andré_scaff 

 

Go to admin and follow this path:

Content -> Design -> Configuration -> Here you will see the listing of theme which is enabled for your store.

 

Click on edit and you will see one section named as "Footer". In Footer, you will find one field named as " Miscellaneous HTML". Put your java script here, it will added to your footer.

sol5.png

Flush the cache after doing the same.

 

if issue solved,Click Kudos & Accept as Solution

Re: How to add a java script in the footer? Magento 2.X

Hi @andré_scaff 

 

If this resolve your issue then Accept it as solution Smiley Happy

Re: How to add a java script in the footer? Magento 2.X

I will test it, and if it works I will do it \o

Thank you so much for the help!

Re: How to add a java script in the footer? Magento 2.X

I've just tested it and it didn't work.

It didn't add the javascript to the footer, actually nothing happened.

Do you know any other way of doing it?

Re: How to add a java script in the footer? Magento 2.X

Hi @andré_scaff 

 

I have put the javascript on shared path and flush the cache so while loading the website it alerts "Hi".

 

See attached screen shot for your reference:

sol11.png

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
alert("Hi");
});
</script>

 

This is the example which I put and got alert. Please try in this way, hope it will work for you as well.

 

if issue solved,Click Kudos & Accept as Solution

Re: How to add a java script in the footer? Magento 2.X

I was able to do it using google tag manager.

 

I'm going to try again using this, I think I forgot to flush the cash, that's why It didn't work actually.

 

Thank you so much for your help!