Simple adding of Google analytics code on a portal dynamic spot item:
<%-- Google Analytics include file for the page --%>
<portal-logic:pageMetaData varname="pageMetaData">
<c:set var="gacode" value="${pageMetaData['ga.code']}" />
<c:if test="${not empty gacode}">
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '${apsgacode}', '<company>.com');
ga('require', 'linkid', 'linkid.js');// page tracking enable
gaFriendly = document.location.indexOf("/!ut");
gaLoc = document.location.href;
if (gaFriendly != -1){
gaLoc = document.location.href.substring(0,gaLoc);
}
ga('set', 'location', gaLoc);
${pageMetaData['ga.option1']}
${pageMetaData['ga.option2']}
${pageMetaData['ga.option3']}
ga('send', 'pageview');
</script>
</c:if>
</portal-logic:pageMetaData>
This code will add a simple support for google analytics on a portal theme page, I added this to the head.jsp file for now but can be included anywhere.
Since we use the page meta data i.e parameters we will be able to use the same theme on many virtual portals.
No comments:
Post a Comment