Philip Lawrence edited this page Oct 17, 2012 · 1 revision

Adobe SiteCatalyst Yii Extension

This covers basic usage for the Adobe SiteCatalyst Yii Extension


Accessing SiteCatalyst in Yii

Since the SiteCatalyst extension is setup as a component, you can simply use the following call to access the extension:


Setting a SiteCatalyst variable

For Adobe SiteCatalyst, you set variables (object properties to be specific) to pass values. For the Yii extension you use a similar setup. All you need to do is set the name of the property to the value you want to pass.

A simple example

A normal call to set a custom variable in JavaScript:

s.eVar25 = 'fooBar';

Within a controller or view, you can do the same as above via the extension:

Yii::app()->siteCatalyst->eVar25 = 'fooBar';
A more complex example

Often you need to push quite a bit of data into SiteCatalyst (which is why you might select using SiteCatalyst over something more simple like Google Analytics). With this extension, that is fairly easy.

For an example, let's push in transaction data when the user completes a checkout via the checkout action within the cart controller. You can see within this example that Yii's relational records can be used (see: $order->Store->Name)



// ...

protected function beforeRender($view)
    $return = parent::beforeRender($view);
    return $return;

public function actionCheckout( )
    // Do some processing here (let's say $order has information about the order)
        // Start the transaction using $order's information
        Yii::app()->siteCatalyst->purchaseID    = $order->OrderID;
        Yii::app()->siteCatalyst->transactionID = $order->OrderID;
        Yii::app()->siteCatalyst->city          = $order->BillingAddress->City;
        Yii::app()->siteCatalyst->zip           = $order->BillingAddress->Zip;
        // Loop through each item that the order had
        $products = array();
        foreach($order->Items as $item)
            $products[] = array(
                'category'  => $item->Category->Name,
                'sku'       => $item->SKU,
                'quantity'  => $item->Quantity,
                'price'     => $item->Price,
        Yii::app()->siteCatalyst->products      = $products;
        // Add in the purchase event
        Yii::app()->siteCatalyst->events       = array('event25','purchase');

Allowed Variables

A majority of the variables you get with a standard SiteCatalyst implementation are included here. Below is a simple list:

  • campaign
  • channel
  • currencyCode
  • eVarN (Where N = any number)
  • events
  • hierN (Where N = any number)
  • pageName
  • pageType
  • purchaseID
  • products
  • propN (Where N = any number)
  • s_account (set via settings/configuration)
  • server
  • state
  • TnT
  • transactionID
  • zip

You can find more information about each of these over within the SiteCatalyst Reference wiki.

Rendering the SiteCatalyst output

Rendering within the extension depends on the way you configured it.

If Auto Rendering is enabled

If auto rendering is enabled and you followed the configuration steps (adding beforeRender call to your controllers) then there is nothing else for you to do to render the JavaScript code.

If Auto Rendering is disabled

If you have auto rendering disabled (which it is by default), then you can call the render() method within your views which will return the rendered SiteCatalyst JavaScript code. In almost all cases, you should use this in your main layout views (e.g. protected/views/layouts/main.php)

<script type="text/JavaScript">
<?php echo Yii::app()->siteCatalyst()->render(); ?>

Note: The render method does not wrap <script></script> tags around the output. If auto-rendering is enabled, CClientScript::registerScript is utilized, otherwise JavaScript code is returned.