I have research on this and I can implement google analytics on a single java page. However, the portal have multiple pages and I cannot repeat it for every single page. For html or php sites, we can easily do it by copying some code into header or footer. What is the best way to do it on Java project ?
Asked
Active
Viewed 1,044 times
3
-
Can you provide some more details about your setup? Some code samples? – XTOTHEL Oct 23 '18 at 02:51
-
Yes, I have updated my question with details. Tks. – user1314404 Oct 23 '18 at 03:21
-
Where do you determine what goes into the of the page? – XTOTHEL Oct 23 '18 at 03:35
-
Actually I don't know how to check it also ... – user1314404 Oct 23 '18 at 06:06
-
Can you open up "WebContent" > index.jsp? – XTOTHEL Oct 23 '18 at 14:19
-
I have change my post to add in more details as requested. If I add google analytics code into the html it is only monitoring only that page access. – user1314404 Oct 26 '18 at 07:23
2 Answers
0
create a common jsp page for your google analysis and import this jsp to your template jsp using c:import you can dynamically change the attribute as per your requirement
c:import example
:display.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:out value="Chaitanya"/>
<c:out value="BeginnersBook.com" />
<c:out value="This is just a String" />
index.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title> JSTL c:import Tag Example</title>
</head>
<body>
<c:import var="mydata" url="/display.jsp"/>
<c:out value="${mydata}"/>
</body>
</html>
Here is a nice post Import content to your Web site from IBM

Bhushan Uniyal
- 5,575
- 2
- 22
- 45
0
we need to add script code in the header of every page. and you already have a separate header.jsp file which is included in every page.
so, you can add code in the just header.jsp
If you are using Google analytics, then
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
</script>
</head>
If you are using a Google tag manager, then
<head>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
</head>

krishna
- 11
- 4