Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Exit Page - How to

Go to End

2 Posts   1889 Views


Community Member, 1 Post

17 October 2009 at 1:03am

Hi there,

just registered for this forum. I already made 3 sites with SilverStripe and it just works like a charm.

The only thing, that i didn't find out is, how to install/configure a "Exit Page". So I did it on my own ... it works, but I'm sure there is a better way to do this (Creating a real http filter instead of replacing external urls within the content ... ?)

The reason for using a exit page is, to have google analytics (or any other) to track how often which external links are being clicked. Maybe there is a better way to do this anyway?

1. I created a Page called and disabled "show in menu"
2. Page.php: I replace all external urls to point to this new page with a GET Parameter 'exiturl'

class Page_Controller extends ContentController {
	function isInternalUrl($url)
		$internal_urls = array('', '', '');
		foreach($internal_urls as $intUrl)	{
			if(strpos($url, $intUrl) === false) {
			} else {
				return true;
		return false;
	public function init() {
		// track all external urls and add exit page
		if(array_key_exists('exiturl',$_GET)) {
			// Add the exiturl to the content
			$this->dataRecord->Content = str_replace('[EXITURL]', $_GET['exiturl'], $this->dataRecord->Content);
		} else {
			// replace external urls with the exit page
			$exitpage = '/exit/?exiturl=';
			$regex = '/https?\:\/\/[^\" ]+/i';
			preg_match_all($regex, $this->dataRecord->Content, $matches);
			foreach($matches[0] as $url) {
				if(!$this->isInternalUrl($url)) {
					$this->dataRecord->Content = str_replace($url, $exitpage . $url, $this->dataRecord->Content);

3. Then I just add "[EXITURL]" within the new page with the editor (if javascript is disabled the user can click on the link, and for SEO purposes) and have a javascript redirect which gets the GET parameter.
<p>Your are leaving and are being redirected to another page.</p>
<p>If you are not being redirected click <a href="[EXITURL]">here</a>.</p>
	<script type="text/javascript">
function gup( name )
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
    return results[1];
		if(location.href.indexOf('exiturl') != -1)

I think you have to add this javascript within the template. The WYSIWYG editor deletes javascripts (as it seems!).

Do you have any ideas if there is an existing solution? Maybe you have a better idea how to realize this?

Thanks in advance



Community Member, 28 Posts

19 October 2009 at 11:25am

Edited: 19/10/2009 11:59am

Hi Wolf

I prefer to track exit links in Google Analytics via onClick events. Here is the google help link:

You can also do this using trackEvent rather than trackPageview so it doesn't inflate your site pages views but I don't have a link handy for that.

You can get some javascript that does this automatically. Google should return some options and you can also do it with jQuery if you prefer.