1
0
mirror of synced 2024-11-30 09:16:06 +03:00
bitrix-module/intaro.retailcrm/classes/general/collector/RetailCrmCollector.php

56 lines
1.8 KiB
PHP
Raw Normal View History

2017-09-04 11:36:04 +03:00
<?php
2019-02-28 14:45:39 +03:00
/**
* @category RetailCRM
* @package RetailCRM\Collector
* @author RetailCRM <integration@retailcrm.ru>
* @license MIT
* @link http://retailcrm.ru
* @see http://retailcrm.ru/docs
*/
2019-02-28 14:45:39 +03:00
/**
* Class RetailCrmCollector
*
* @category RetailCRM
* @package RetailCRM\Collector
2019-02-28 14:45:39 +03:00
*/
2017-09-04 11:36:04 +03:00
class RetailCrmCollector
{
public static $MODULE_ID = 'intaro.retailcrm';
public static $CRM_COLL_KEY = 'coll_key';
public static $CRM_COLL = 'collector';
2019-02-28 14:45:39 +03:00
/**
* Add Daemon Collector script
*
* @return bool
*/
2017-09-04 11:36:04 +03:00
public static function add()
{
$keys = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL_KEY, 0));
$collector = COption::GetOptionString(self::$MODULE_ID, self::$CRM_COLL, 0);
$request = \Bitrix\Main\Context::getCurrent()->getRequest();
2017-09-04 11:36:04 +03:00
if ($collector === 'Y' && !empty($keys[SITE_ID]) && $request->isAdminSection() !== true) {
2017-09-04 11:36:04 +03:00
global $USER;
$params = array();
if ($USER->IsAuthorized()) {
$params['customerId'] = $USER->GetID();
}
$str = "<script type=\"text/javascript\">
(function(_,r,e,t,a,i,l){_['retailCRMObject']=a;_[a]=_[a]||function(){(_[a].q=_[a].q||[]).push(arguments)};_[a].l=1*new Date();l=r.getElementsByTagName(e)[0];i=r.createElement(e);i.async=!0;i.src=t;l.parentNode.insertBefore(i,l)})(window,document,'script','https://collector.retailcrm.pro/w.js','_rc');
_rc('create', '" . $keys[SITE_ID] . "', " . json_encode((object) $params) . ");
_rc('send', 'pageView');
</script>";
2019-02-28 14:45:39 +03:00
\Bitrix\Main\Page\Asset::getInstance()->addString($str, true);
return true;
2017-09-04 11:36:04 +03:00
} else {
return false;
}
}
}