Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Exit Page - How to

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

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

Page: 1
Go to End
Author Topic: 1335 Views
  • w0lf
    Community Member
    1 Post

    Exit Page - How to Link to this post

    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 www.somehost.com/Exit 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('somehost.com', 'www.somehost.com', 'sta.www.somehost.com');
          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 www.somehost.com 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


  • Greg1
    Community Member
    28 Posts

    Re: Exit Page - How to Link to this post

    Hi Wolf

    I prefer to track exit links in Google Analytics via onClick events. Here is the google help link: http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55527

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.