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)
    {
        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);

        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.
>>
>

Reply via email to