Difference between revisions of "How to add custom tracking JavaScript code at the bottom of each aMember's page"

From aMember Pro Documentation
Jump to: navigation, search
Line 1: Line 1:
 
Add this code to [[site.php file]]:
 
Add this code to [[site.php file]]:
 
<source>
 
<source>
<?php
 
 
 
// Setup hook that will be executed before page render
 
// Setup hook that will be executed before page render
 
Am_Di::getInstance()->hook->add(Am_Event::BEFORE_RENDER, 'addTrackingCode');
 
Am_Di::getInstance()->hook->add(Am_Event::BEFORE_RENDER, 'addTrackingCode');
  
 
function addTrackingCode(Am_Event $e){
 
function addTrackingCode(Am_Event $e){
 
 
     // Do not add tracking code to Admin pages.  
 
     // Do not add tracking code to Admin pages.  
 
     if(defined('AM_ADMIN')) return;
 
     if(defined('AM_ADMIN')) return;
 
  
 
     $view = $e->getView();
 
     $view = $e->getView();
Line 17: Line 13:
 
     $view->placeholder('body-finish')->append(<<<EOT
 
     $view->placeholder('body-finish')->append(<<<EOT
 
<script>
 
<script>
 
 
PUT YOUR TRACKING JAVASCRIPT CODE HERE
 
PUT YOUR TRACKING JAVASCRIPT CODE HERE
 
 
</script>
 
</script>
 
EOT
 
EOT
 
         );
 
         );
 
}
 
}
 
 
</source>
 
</source>

Revision as of 03:11, 3 November 2015

Add this code to site.php file:

// Setup hook that will be executed before page render
Am_Di::getInstance()->hook->add(Am_Event::BEFORE_RENDER, 'addTrackingCode');
 
function addTrackingCode(Am_Event $e){
    // Do not add tracking code to Admin pages. 
    if(defined('AM_ADMIN')) return;
 
    $view = $e->getView();
 
    // Output your code before closing </body> tag
    $view->placeholder('body-finish')->append(<<<EOT
<script>
PUT YOUR TRACKING JAVASCRIPT CODE HERE
</script>
EOT
        );
}