Hi Martin,

With pleasure. I would be glad to add it to the wiki, just please tell me
in which section and how to request an account (or maybe you asked me if I
wanted -you- to add it to the wiki :) )

About your 2 comments:

- The page instance is passed to the behavior because I had supposed the
behavior will likely be added on a 'base' page. Like this, every child
pages will automatically have their own GA script, simply with:
this.add(new GoogleAnalyticsBehavior(this));
But I can provide 2 constructors, one with WebPage, the other with
Class<WebPage>. #getURL() will then deals with the type instead of the
instance, which is straightforward to update.

- renderFullUrl: I also guessed GA script would have expected the full url
(including the protocol, the port and the domain). I was so confident that
I deployed with that change (yes, I did). As the result, the effect is
dramatic: in the report, all visited pages was starting with "/http://";
(with the "/" at the beginning), instead of "/context/my/path/to/page" as
expected.

Thanks again & best regards,
Sebastien.


On Mon, Oct 29, 2012 at 9:02 AM, Martin Grigorov <mgrigo...@apache.org>wrote:

> Hi Sebastien,
>
> Thanks for sharing this solution!
> I find it very useful.
> Do you want to add it in the Wiki so it will be easier to find and
> "part of the documentation".
>
> See few comments inline.
>
> On Sun, Oct 28, 2012 at 3:49 PM, Sebastien <seb...@gmail.com> wrote:
> > Hi,
> >
> > For whom might be interested, here is a solution on how to remove ?1
> params
> > from tracked page's URL on GoogleAnalytics. This follows a thread
> entitled
> > "I would url clear, without jsessionid and ?1"
> > To achieve this, the approach is to not attempt to remove/adapt ?1 params
> > from statefull page's URL, but rather supply a "clean" URL to the GA
> > javascript object: _gaq.push(['_trackPageview', 'the/clean/url']);
> >
> > For this cooking recipe we need:
> > 1/ the GA client script in a js-templated file (ie: my/package/gaq.js) so
> > the URL value can be supplied through a variable:
> > _gaq.push(['_trackPageview', '${url}']);
> > 2/ a behavior, that will:
> > 2a/ resolves the URL (ie: /context/page)
> > 2b/ de-templates the js file, with the url value, using a
> > TextTemplateResourceReference
> > 2c/ renders the js file back to the page.
> >
> > Then, add the behavior to your (base) page, and that's it.
> > The behavior looks like:
> >
> > class GoogleAnalyticsBehavior extends Behavior
> > {
> >     private static final long serialVersionUID = 1L;
> >
> >     private final String url;
> >
>
>
> >     public GoogleAnalyticsBehavior(final WebPage page)
> >     {
>
> No need to pass an instance of WebPage. You need just its class.
>
> >         this.url = this.getUrl(page);
> >     }
> >
> >     private String getUrl(WebPage page)
> >     {
> >         Url pageUrl = Url.parse(page.urlFor(page.getClass(),
> > null).toString());
> >         Url baseUrl = new
> > Url(page.getRequestCycle().getUrlRenderer().getBaseUrl());
> >
>
> >         baseUrl.resolveRelative(pageUrl);
>
> No need to play with the base url and calculate the urls yourself.
> Use:
> Url fullUrl = urlRenderer.renderFullUrl(pageUrl)
>
> >
> >         return String.format("%s/%s", page.getRequest().getContextPath(),
> > baseUrl);
> >     }
> >
> >     private IModel<Map<String, Object>> newResourceModel()
> >     {
> >         Map<String, Object> map = new HashMap<String, Object>();
> >         map.put("url", this.url);
> >
> >         return Model.ofMap(map);
> >     }
> >
> >     private ResourceReference newResourceReference()
> >     {
> >         return new
> > TextTemplateResourceReference(GoogleAnalyticsBehavior.class, "gaq.js",
> > this.newResourceModel());
> >     }
> >
> >     @Override
> >     public void renderHead(Component component, IHeaderResponse response)
> >     {
> >         super.renderHead(component, response);
> >
> >
> >
> response.render(JavaScriptHeaderItem.forReference(this.newResourceReference(),
> > "gaq"));
> >     }
> > }
> >
> >
> > Thanks to Martin (I would say: again!) to have suggested the right
> pointers.
> > Sebastien.
> >
> > On Fri, Oct 26, 2012 at 1:17 AM, Sebastien <seb...@gmail.com> wrote:
> >
> >> Hi Martin,
> >>
> >> Thanks for your answer! Yes, I think it - indirectly - answers the need!
> >>
> >> In short: Google Analytics does not take into account the canonical
> links
> >> directly (it appears to be for indexing purpose only). However, you put
> me
> >> on the right direction, and a simple solution is provided here:
> >> http://stackoverflow.com/questions/9103794/canonical-url-in-analytics
> >>
> >> I will give this a try and will let you know!
> >>
> >> Thanks again & best regards,
> >>
> >> Sebastien.
> >>
> >> On Thu, Oct 25, 2012 at 5:17 PM, Martin Grigorov <mgrigo...@apache.org
> >wrote:
> >>
> >>> Hi Sebastien,
> >>>
> >>> Is
> >>>
> http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html
> >>> a solution for this use case ?
> >>>
> >>> On Thu, Oct 25, 2012 at 5:42 PM, Sebastien <seb...@gmail.com> wrote:
> >>> > Hi,
> >>> >
> >>> > I have a question related to this thread, how is it possible to have
> a
> >>> > variable name for ?1, ?2 ?
> >>> > ie: ?state=1, ?state=2 (or another variable name)
> >>> > Is there any existing IRequestMapper for that for instance?
> >>> >
> >>> > One use case, is that google analytics allows to not take into
> account
> >>> some
> >>> > url variables so pages are not considered as distinct (MyPage?1 and
> >>> > MyPage?2 should sums stats for only one page: MyPage, which is not
> the
> >>> case
> >>> > yet)
> >>> >
> >>> > Thanks in advance!
> >>> > Sebastien.
> >>>
> >>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to