Create an Action or Redirect

Example

For example, let's create a new redirect “Myredirect”.

Create a file /application/redirects/myredirect.php.

<?php
namespace Redirects;
 
use Component\Streams\Model\BaseStream;
use Component\Clicks\Model\RawClick;
use Component\StreamActions\AbstractAction;
 
class myredirect extends AbstractAction
{
    protected $_name = 'MyRedirect'; // name of the action
    protected $_weight = 100;
 
    public function getType()
    {
        return self::TYPE_REDIRECT;
        // return self::TYPE_OTHER; // mark the script as "Action" if you need 
    }
 
    protected function _execute(BaseStream $stream, RawClick $rawClick)
    {
        // Here is the code of our script 
        $this->addHeader("Location: " . $rawClick->getDestination());   // Sending HTTP-header
        $this->setContent('Redirecting...');                  // Display text on the page
    }
}

It is important that the file name be the same as the class name.

What methods are available in $stream and $rawClick?

Read at the pages $rawClick, $stream.

How to add a remarketing code or metrics?

Here is an example of adding the Facebook pixel.

Create a file application/redrects/remarketing.php. With code:

<?php
namespace Redirects;
 
use Component\Streams\Model\BaseStream;
use Component\Clicks\Model\RawClick;
use Component\StreamActions\AbstractAction;
 
class example extends AbstractAction
{
    protected $_name = 'Example';
    protected $_weight = 100;
 
    protected function _execute(BaseStream $stream, RawClick $rawClick)
    {
         $this->setContent($this->_getJavascriptRedirect($stream, $rawClick));
    }
 
    private function _getJavascriptRedirect(BaseStream $stream, RawClick $rawClick)
    {
    $remarketing = <<<EOF
    <!-- Facebook Pixel Code -->
    <script>
    !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
    n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
    n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
    document,'script','https://connect.facebook.net/en_US/fbevents.js');
 
    fbq('init', '1914721942087471');
    fbq('track', "PageView");</script>
    <noscript><img height="1" width="1" style="display:none"
    src="https://www.facebook.com/tr?id=1914721942087472&ev=PageView&noscript=1"
    /></noscript>
    <!-- End Facebook Pixel Code -->
EOF;
 
    $code = '<html>
    <head>
        ' . $remarketing . '
        <meta http-equiv="REFRESH" content="1; URL=\'' . $rawClick->getDestination() . '\'">            
        <script type="text/javascript">window.location = "' . $rawClick->getDestination() . '";</script>
    </head>
    <body>
        The Document has moved <a href="' . $rawClick->getDestination() . '">here</a>
    </body>
    </html>';
 
    return $code ;
  }
}

The page referenced by REMOTE must return only the new address

http://domain.com/page

or domain

domain2.com