Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Google Analytics

Alternative Languages: 日本語

Configuring Liferay to work with Google Analytics is very simple.

To enable Google Analytics support, go to the Manage Pages screen for the community for which you want to enable support. You can do this through the Control Panel by going to either the Organizations or Communities link in the Portal section, and then clicking Actions → Manage Pages for the community or organization you want to analyze. Click the Settings tab. Click the Monitoring Tab. Put your Google Analytics ID (which should have been provided to you when you signed up for the service) in the field and click Save. All of the pages in the community you selected will now have the Google Analytics code in them and will be tracked.


The latest code from Google Analytics looks like this:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

Slightly older code will look like this:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
</script>

Here's the even-older code (Note from Google):

<script type="text/javascript" src=" http://www.google-analytics.com/urchin.js "></script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x"
urchinTracker();
</script>

Where xxxxxx-x is your id, which you can find in the Google Analytics setup pages.


There are three places in Liferay where you can place the Google Analytics code.

Portal Wide (One site wide domain) #

The typical scenario is that you want to use a single Google Analytics account to track an entire portal deployment.

You can add the code to the following file:

/html/common/themes/bottom-ext.jsp

For jsp themes, make sure /html/themes/[theme_name]/templates/portal_normal.jsp contains the following line:

<liferay-util:include page="/html/common/themes/bottom-ext.jsp" />

OR if you're using a Velocity theme, make sure /html/themes/[theme_name]/templates/portal_normal.vm contains the following line:

$taglibLiferay.include("/html/common/themes/bottom-ext.jsp")

Therefore, you can add the Google Analytics code in /html/common/themes/bottom-ext.jsp to make Google Analytics configuration global for your portal.

You'll find this file in the Liferay war. If your portal is running in the root context of apache-tomcat-5.5.x, then the path is:

${CATALINA_HOME}/webapps/ROOT/html/common/themes/bottom-ext.jsp

In Manage Pages (The GUI method) #

  1. From the Communities portlet or the Enterprise Admin portlet, select Manages Pages for a community or organization.
  2. Select the Settings tab.
  3. Select the Monitoring tab.
  4. Enter your Google Analytics ID.

In Themes (Virtual Hosting?) #

"Why would I want to place the Analytics code in a theme?", you ask. Well, If you're going to use virtual hosting and want to have different Google Analytics accounts for each domain, you could design a different theme for each Community which hosts a domain. Place the appropriate Google Analytics code for a given domain in the appropriate theme. Do this for each Community hosting a domain, and have them tracked individually.

In any theme, place the above code just before the closing html or body tag. These you'll find in the following file /html/themes/[theme_name]/templates/portal_normal.[jsp|vm]

e.g.

[SNIP/]
...
    <%@ include file="bottom.jsp" %>

<liferay-util:include page="/html/common/themes/bottom-ext.jsp" />
<liferay-util:include page="/html/common/themes/session_timeout.jsp" />
<liferay-util:include page="/html/common/themes/sound_alerts.jsp" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try{
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._trackPageview();
} catch(err) {}
</script>

</body>

</html>

PS: The liferay site has it in /html/common/themes/bottom-ext.jsp so that it applies site wide, regardless of theme.


PSS: SiteScan will scan your site and check if every page has the javascript correct.

0 Attachments
63923 Views
Average (4 Votes)
The average rating is 3.75 stars out of 5.
Comments
Threaded Replies Author Date
Enter your Google analytics id: UA-XXXXX-X Ricardo Javier Barbieri April 7, 2009 9:24 PM
I added my analytics id per the GUI method... Al Zoid November 9, 2009 11:05 AM
Hi I went with the Control Panel > Manage... Garry Donnelly April 22, 2010 3:03 PM
Hello. I need help. I do not want to connect to... Arash Ghobadiyan June 19, 2010 4:11 AM
Any way to send a optional variable? Like in... Doug Molineux March 22, 2011 11:18 AM
Have you worked with Google Analytics filters?... Fidel Santiago April 1, 2011 3:42 AM
Has anyone set up monitoring with their own... Kirk Stork June 29, 2011 7:11 AM
When I added analytics support, I got analytics... Milan Palian March 7, 2012 11:19 PM

Enter your Google analytics id: UA-XXXXX-X
Posted on 4/7/09 9:24 PM.
I added my analytics id per the GUI method mentioned above. My google analytics account is still showing as 'Tracking Unknown'.



Update: I tried all methods listed above and analytics account still shows 'Tracking Unknown'

Any sugggestions>

Thank you,

Al
Posted on 11/9/09 11:05 AM.
Hi

I went with the Control Panel > Manage Pages option and it looks fantastic. You get a great insight into who's accessing your site with Analytics and Google has Webmaster Tools now too. I posted a detailed guide on Analytics/Liferay/Webmaster Tools for those interested in this entry: http://www.greatwhiteit.com/web/guest/home/-/blogs/google-webmaster-tools-and-go­ogle-analytics-in-liferay

-Garry
Posted on 4/22/10 3:03 PM in reply to Al Zoid.
Hello.
I need help.
I do not want to connect to the Google-analytics but I'll do anything I'm still connected.
What do you do?
Posted on 6/19/10 4:11 AM.
Any way to send a optional variable? Like in JGoogleAnalytics you can do this:

JGoogleAnalyticsTracker tracker = new JGoogleAnalyticsTracker(
"Sensor List", "MY-OPTIONAL-VARIABLE", "UA-21921468-6");
Posted on 3/22/11 11:18 AM.
Have you worked with Google Analytics filters? Would be great to filter out administrative tasks done by certain users.

I have been looking at the Google documentation but I haven't found any idea or hint.

Any idea or suggestion?

Thanks, Fidel.
Posted on 4/1/11 3:42 AM.
Has anyone set up monitoring with their own instance of Urchin? Tips or howtos would be helpful...
Posted on 6/29/11 7:11 AM in reply to Fidel Santiago.
When I added analytics support, I got analytics for the whole community, how do you get a "by page" breakdown?
Posted on 3/7/12 11:19 PM.