This discussion is archived
10 Replies Latest reply: Oct 31, 2012 3:42 AM by 943086 RSS

Dynamic pagetitle in event code for webcenter analytics page views

943086 Newbie
Currently Being Moderated
Hi all,

we want to implement analytics on page views in our Webcenter Portal portal. In the DevGuide (Chapter 47.2.3.1) I found a piece of code that has to be added to each page for which you want to send the page events to the Analytics Collector.
I have 2 problems with this piece of code that I don't know how to circumvent.
1) The pagename is hardcoded in the example. I would like to make it dynamic in order to be able to use the same piece of code in all my pages. Does anybody know how I can achieve this?
2) The piece of code has to be added to each page. As we want to gather statistics on both pages created at design time as well as pages created at run-time, we would like to add this piece of code "automatically" to each and every page that is created (both design-time and run-time).

Does anybody know how I can achieve both things mentioned above. I have been thinking of adding the code to the page-template, but I am not sure whether this is possible or not. Also I am not sure if I can get the page-title there, since it is different for each page.

Any help would be appreciated.

regards,

Harold
  • 1. Re: Dynamic pagetitle in event code for webcenter analytics page views
    Bijesh Krishnadas Journeyer
    Currently Being Moderated
    One option may be to use the navigation model EL to obtain the current selection's title.
    #{navigationContext.currentNavigationModel.currentSelection.title}
    And yes, this EL works in the page template too.

    Edited by: Bijesh Krishnadas on Oct 1, 2012 5:49 PM
  • 2. Re: Dynamic pagetitle in event code for webcenter analytics page views
    943086 Newbie
    Currently Being Moderated
    Hi Bijesh,

    do you happen to know how I can access this from a java class implementing a pagePhaseListener? I am using a listener to make sure the method is executed on every page.

    regards,

    Harold
  • 3. Re: Dynamic pagetitle in event code for webcenter analytics page views
    Bijesh Krishnadas Journeyer
    Currently Being Moderated
    Hi Harold,

    Can't you include the code in the page template? I would assume it will execute on each page load.
  • 4. Re: Dynamic pagetitle in event code for webcenter analytics page views
    943086 Newbie
    Currently Being Moderated
    Hi Bijesh,

    my problem is, I can't execute EL code in javascript (see EL expression in Javascript The method of collecting page view statistics as mention in the DevGuide (Chapter 47) is using javascript to actually perform the registration of the pageview.

    regards,

    Harold
  • 5. Re: Dynamic pagetitle in event code for webcenter analytics page views
    Bijesh Krishnadas Journeyer
    Currently Being Moderated
    Hi Harold,

    I see what you mean. In fact, I realised that there is no clean way of using a on-load clientListener within a page template. That's a bummer.

    Anyway, to evaluate an EL in code you do something like this. However far more easier, if you use the ADFUtils and JSFUtils classes that ships with a lot of the sample code from Oracle.
            FacesContext fc = FacesContext.getCurrentInstance();  
            ELContext elctx = fc.getELContext();  
            ExpressionFactory elFactory =  
                  fc.getApplication().getExpressionFactory();  
            elFactory.createValueExpression(elctx
                                                , "#{navigationContext.currentNavigationModel.currentSelection.title}"
                                                , String.class);
    Having said that, you will need to check which phase gives you the most satisfactory results. I found phaseId 14 (there is no equivalent in JSF) to be the most effective.

    NOTE: I don't think using the navigationModel is fool-proof. For e.g. when you go to the Admin screen, the navigationModel retains the existing currentSelection. There may be other such quirks. A simpler route may be to use the viewId instead of a page name. It would be a headache analysing the data though.

    I can't find an API to map the viewId to the equivalent node on the navigation model (would've been the best solution).
  • 6. Re: Dynamic pagetitle in event code for webcenter analytics page views
    943086 Newbie
    Currently Being Moderated
    Hi Bijesh,

    you say phase 14 gives you the best result. I was using the RenderResponse Phase, but I find my code being executed also when the page is partially (re-)rendered. This seems to be happening at phase 14 as well. Do you know of a way to distinguish between page load and partial page load?

    regards,

    Harold
  • 7. Re: Dynamic pagetitle in event code for webcenter analytics page views
    Bijesh Krishnadas Journeyer
    Currently Being Moderated
    Unfortunately, no idea how to handle that. It may be a good idea to ask this in the ADF forum.

    To further muddle this: I am wondering if you can use a custom view handler (extending oracle.webcenter.portalframework.sitestructure.handler.CustomViewHandler) to log the view event. This is where Spaces seems to have its Analytics code (in method getPageTargetViewId).
  • 8. Re: Dynamic pagetitle in event code for webcenter analytics page views
    943086 Newbie
    Currently Being Moderated
    Hi Bijesh,

    implementing a CustomViewHandler seems to do the trick. It even only seems to be executed when the page is requested, not when PPR occurs.

    thanks,

    Harold
  • 9. Re: Dynamic pagetitle in event code for webcenter analytics page views
    Bijesh Krishnadas Journeyer
    Currently Being Moderated
    Excellent. Would you mind posting your code here for future visitors?
  • 10. Re: Dynamic pagetitle in event code for webcenter analytics page views
    943086 Newbie
    Currently Being Moderated
    Hi Bijesh,

    what I dit to register pageviews of the custom portal in the analytics schema is:

    create a class AnalyticsCustomViewHandler which extends CustomViewHandler:
    public class AnalyticsCustomViewHandler extends CustomViewHandler {
        private static int RESPONSETIME = 100;
        private static String SPACENAME = "YourPortalName";
        
        private static final ADFLogger logger =
            ADFLogger.createADFLogger(AnalyticsCustomViewHandler.class);
    
       public AnalyticsCustomViewHandler(ViewHandler viewHandler) {
            super(viewHandler);
        }
    
        @Override
        protected String getPageTargetViewId(CustomPortalNavigation pCustomPortalNavigation,
                                             SiteStructureResource pSiteStructureResource,
                                             Transferable pTransferable,
                                             boolean pBoolean, Scope pScope) {
    
            String viewId =
                super.getPageTargetViewId(pCustomPortalNavigation, pSiteStructureResource,
                                          pTransferable, pBoolean, pScope);
    
            sendPageViewToAnalytics(viewId);
    
            return viewId;
        }
    
        public static void sendPageViewToAnalytics(String pViewId) {
            logger.entering(AnalyticsCustomViewHandler.class.getName(),
                            "sendPageViewToAnalytics");
            
            if (StringUtils.isBlank(pViewId)) {
                logger.info("Encountered blank viewId");
                return;
            }
            
            if (!AnalyticsUtil.isSendingEvents()) {
                logger.info("Analytics is not sending events.");
                return;
            }
    
            String resourceId = pViewId;
            String viewId = pViewId;
              // Retrieve page path from viewId
            String sSearchString = "/oracle/webcenter/portalapp/pages";
            int pagePathStart = pViewId.indexOf(sSearchString);
            if (pagePathStart > -1) {
                pagePathStart += sSearchString.length();
                viewId = pViewId.substring(pagePathStart);
            }
            int extensionIndex = viewId.indexOf(".jspx");
            if (extensionIndex > -1) {
                viewId = viewId.substring(0, extensionIndex);
            }
            FacesContext ctx = FacesContext.getCurrentInstance();
            HttpServletRequest request = (HttpServletRequest)ctx.getExternalContext().getRequest();
            String requestUser = request.getRemoteUser();
    
            AnalyticsUtil.sendPageViewEvent(resourceId, SPACENAME,
                                            requestUser, RESPONSETIME,
                                            viewId, false, request);  
            logger.info("Page event sent for viewId " + viewId);
            logger.exiting(AnalyticsCustomViewHandler.class.getName(),
                           "sendPageViewToAnalytics");
    
        }
    }
    Then I registered this CustomViewEvent in the faces-config.xml as the view-handler to be used.

    Note: only pages that are navigated to through an navigation model event seem to be registered this way. If you want to register pages that are navigated to directly you may need to use another construction. In this case a pagePhaseListener might be the best option, but then you have to set up something to prevent PPR action as pageviews.

    regards,

    Harold

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points