Custom Action/redirect Script

That feature available only for PRO or higher editions

How to create a custom redirect script

All the redirect scripts must be located in /application/redirects/.

Let's create a script “FBPixel”. Create new file %%fbpixel.php with the code. Every time when you creating new scripts, make sure that class name and the file name are the same.

<?php
namespace Redirects;
 
use Traffic\Actions\AbstractAction;
 
class fbpixel extends AbstractAction
{
    protected $_name = 'FBPixel';     // action/redirect name
    protected $_weight = 100;
 
    public function getType()
    {
        return self::TYPE_REDIRECT;              # or self::TYPE_OTHER
    }
 
    protected function _execute()
    {
         $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;
    $url = $this->getActionPayload();
    $code = '<html>
    <head>
        ' . $remarketing . '
        <meta http-equiv="REFRESH" content="1; URL=\'' . $url. '\'">            
        <script type="text/javascript">window.location = "' . $url . '";</script>
    </head>
    <body>
        The Document has moved <a href="' . $url . '">here</a>
    </body>
    </html>';
          $this->setContent($code);
    }
}

Avaiable methods

Method Description
$this->getRawClick() Get object RawClick
$this->getStream() Get object BaseStream
$this->getCampaign() Get object Campaign
$this->getLanding() Get object Landing
$this->getOffer() Get object Offer
$this->getRequest() Get object Request
$this->getActionPayload() Get action payload after macros are processed
$this->getRawActionPayload() Get action payload before macros are processed
$this->getActionOptions() Get action options
$this->addHeader($headerLine) Add header line to the response
$this->redirect($url) Perform redirect to an URL
$this->setContent($text) Send any content
$this->setContentType($contentType) Set HTTP content type
$this->setStatus($httpStatusCode) Send HTTP header status
$this->setDestinationInfo($string) Set value for “Destination” that you see in Click Log