@Kam-nyc,
There are 4 ways that you can add custom javascript to a page in AEM, highlighted in this blog, https://sourcedcode.com/blog/aem/how-to-include-javascript-for-an-aem-website
- HTML Event Attributes
- Inline JavaScript
- Internal Client Libraries JavaScript
- External JavaScript
One of the ways that you can easily get JavaScript( without any setup or configurations) to run on your website is #2, from the list, inline Javascript: As you can see, you can just insert a block of code in your HTML.
If you are using WCM Core Components, you can overlay the basepage component, specifically this script, http://localhost:4502/crx/de/index.jsp#/apps/core/wcm/components/page/v2/page/footer.html.
The outcome of your HTML is expected to look like:
<!DOCTYPE html>
<html>
<head>
<title>Inline JavaScript Example</title>
</head>
<body>
<h1 id="intro">Hello World</div>
<script type="text/javascript">
var digitalDataLayer = {
environment: {
environmentVersion: "6.0.5.1",
environmentName: "production",
siteName: "SourcedCode.com",
statusCode: 200
},
target: {},
page: {
pageInfo: {
pageName: "home",
pageReferrer: document.referrer,
pageSiteSection: "homepage",
pageSiteSubsection: "",
pageType: "homepage",
pageURL: "https://www.sourcedcode.com"
}
}
}
</script>
</body>
</html>
I hope this helps,
Brian.