Thx Kieran for the nice example.  That's great.

From: Kieran Kelleher [mailto:[email protected]]
Sent: Thursday, June 14, 2012 12:09 PM
To: Mark Cassidy
Cc: [email protected]
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. :-)

java
-------

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 = ('https:' == 
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;
            }
}



html
--------

<wo:ERXJavaScript scriptString = "$gaScript"></wo:ERXJavaScript>




On Jun 14, 2012, at 11:51 AM, Mark Cassidy wrote:


Hi,

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.

Thanks for any help,
Mark



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      
([email protected]<mailto:[email protected]>)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/kelleherk%40gmail.com

This email sent to [email protected]<mailto:[email protected]>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to