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

From aMember Pro Documentation
Revision as of 04:27, 24 March 2016 by Caesar (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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, function (Am_Event $e) {
    //ensure we execute this code only once
    static $js_adedd = false;
    if ($js_adedd) return;
    $js_adedd = true;
 
    // 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
        );
});