RE: ERXPageTracker question
RE: ERXPageTracker question
- Subject: RE: ERXPageTracker question
- From: Mark Cassidy <email@hidden>
- Date: Thu, 14 Jun 2012 16:17:11 +0000
- Thread-topic: ERXPageTracker question
Thx Kieran for the nice example. That’s great.
From: Kieran Kelleher [mailto:email@hidden]
Sent: Thursday, June 14, 2012 12:09 PM
To: Mark Cassidy
Cc: email@hidden
Subject: Re: ERXPageTracker question
You can just roll your own tracker and track any string you like (build a pseudo URL, for example frameworkname/WOComponentname), since component action URLs won't be of much use I think.
Here is an example of a custom tracker component that resides in an application PageWrapper - it should be obvious how it works. Copy/paste/modify/profit. :-)
package wk.cheetah.statistics;
import org.apache.log4j.Logger;
import wk.foundation.WKStringUtilities;
import wk.webobjects.appserver.WKAbstractStatelessComponent;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
public class CTPageTracker extends WKAbstractStatelessComponent {
@SuppressWarnings("unused")
private static final Logger log = Logger.getLogger(CTPageTracker.class);
public CTPageTracker(WOContext context) {
super(context);
}
private String _gaScript;
/** @return the script for google analytics page tracking */
public String gaScript() {
if ( _gaScript == null ) {
StringBuilder b = new StringBuilder();
b.append("var _gaq = _gaq || [];\n");
b.append("_gaq.push(['_setAccount', 'ENTER-YOUR-OWN-ID-HERE']);");
b.append("_gaq.push(['_setDomainName', 'none']);");
b.append("_gaq.push(['_setAllowLinker', true]);");
String pageName = null;
WOComponent page = context().page();
if (page != null) {
String frameworkName = page.frameworkName();
if (frameworkName == null) {
frameworkName = "app";
}
pageName = "/" + frameworkName + "/" + WKStringUtilities.lastElementOfString(page.name(), ".");
} else {
pageName = "UNKNOWN";
}
if (log.isDebugEnabled())
log.debug("pageName = " + (pageName == null ? "null" : pageName.toString()));
b.append("_gaq.push(['_trackPageview','" + pageName + "']);\n");
b.append("(function() {\n");
b.append(" var ga = document.createElement('script'); ga.type = 'text/_javascript_'; ga.async = true;\n");
b.append(" ga.src = "" == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n");
b.append(" var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n");
b.append("})();\n");
_gaScript = b.toString();
}
return _gaScript;
}
}
<wo:ERXJavaScript
scriptString
=
"$gaScript"></wo:ERXJavaScript>
On Jun 14, 2012, at 11:51 AM, Mark Cassidy wrote:
If we used ERXPageTracker with Component Actions would that be sufficient for Google Analytics? --Don’t want to use Direct Actions if we can help it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden