package com.worldturner.commons.wicket.googleanalytics; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; import com.worldturner.commons.wicket.panel.GenericPanel; /** * Generates javascript for google analytics asynchronous (new) tracking code. The model is the url that is reported to * the tracker, which can also be something other than a URL, such as the java class name of the most important panel on * a page. The account name is stored in a separate model. * * @author Erwin Bolwidt (ebolwidt@worldturner.nl) */ public class GoogleAnalyticsScriptPanel extends GenericPanel { private IModel accountNameModel; public GoogleAnalyticsScriptPanel(String id, String url, String account) { this(id, new Model(url), new Model(account)); } public GoogleAnalyticsScriptPanel(String id, IModel urlModel, IModel accountNameModel) { super(id, urlModel); this.accountNameModel = accountNameModel; } public GoogleAnalyticsScriptPanel(String id, IModel urlModel) { this(id, urlModel, null); } public GoogleAnalyticsScriptPanel(String id) { this(id, (IModel) null, (IModel) null); } @Override protected void initializeGui() { super.initializeGui(); add(new Label("accountName", accountNameModel).setRenderBodyOnly(true)); add(new Label("trackingUrl", getModel()).setRenderBodyOnly(true)); } @Override protected void onDetach() { super.onDetach(); if (accountNameModel != null) { accountNameModel.detach(); } } public void setAccountName(String accountName) { this.accountNameModel = new Model(accountName); } public IModel getAccountNameModel() { return accountNameModel; } public void setAccountNameModel(IModel accountNameModel) { this.accountNameModel = accountNameModel; } }