Created
November 22, 2016 11:55
-
-
Save mhz-tamb/cc6f3867e458158f76e7794223c39475 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace DevGroup; | |
use Bitrix\Main\Config\Option; | |
use Bitrix\Main\Context; | |
use Bitrix\Main\EventManager; | |
use Bitrix\Main\HttpContext; | |
use Bitrix\Main\Page\Asset; | |
use Bitrix\Main\Page\AssetLocation; | |
use Bitrix\Main\Web\Json; | |
/** | |
* Class: Analytics | |
* Integration with Google Analytics | |
*/ | |
class Analytics | |
{ | |
protected static $gaEvents = []; | |
/** | |
* Initial | |
*/ | |
public static function init() | |
{ | |
$context = Context::getCurrent(); | |
if (!$context instanceof HttpContext) { | |
return null; | |
} | |
// Force save product view enable | |
// Required for triggering OnBeforeViewedAdd and OnViewedAdd events | |
if ('Y' !== Option::get('sale', 'product_viewed_save', 'Y')) { | |
Option::set('sale', 'product_viewed_save', 'Y'); | |
} | |
// Remove views product from session for triggering events | |
if (!empty($_SESSION['VIEWED_PRODUCT'])) { | |
$_SESSION['PREVIOUS_VIEWED_PRODUCT'] = $_SESSION['VIEWED_PRODUCT']; | |
$_SESSION['VIEWED_PRODUCT'] = -1; | |
} | |
$em = EventManager::getInstance(); | |
$em->AddEventHandler('sale', 'OnBeforeViewedAdd', [static::class, 'handleOnBeforeViewedAdd']); | |
static::addHeadScript(); | |
} | |
/** | |
* Handle OnBeforeViewedAdd event | |
* @param array $arFields | |
*/ | |
public static function handleOnBeforeViewedAdd($arFields) | |
{ | |
echo 123; die; | |
} | |
protected static function addHeadScript() | |
{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment