Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
analytics.php
1<?php
2
4
5use Bitrix\Calendar\Core\Base\SingletonTrait;
7
9{
10 use SingletonTrait;
11
12 public const CLIENT_STARTED = 'multiple';
13 public const MANAGER_STARTED = 'manager_starting';
14
15 protected const TOOL_CALENDAR = 'calendar';
16 protected const CATEGORY_SLOTS = 'slots';
17
18 protected const CONTEXT_CALENDAR = 'calendar';
19 protected const CONTEXT_CRM = 'crm';
20
21 protected const EVENT_LINK_CREATED = 'link_created';
22 protected const EVENT_MEETING_PLACED = 'meeting_placed';
23 protected const EVENT_CHAT_STARTED = 'chat_started';
24 protected const EVENT_CALL_STARTED = 'call';
25
26 protected const LINK_CREATE_METHOD_CRM_SEND = 'crm_send';
27
28 protected const TYPE_SOLO = 'solo';
29 protected const TYPE_MULTIPLE = 'multiple';
30
31 public function sendLinkSent(Link\CrmDealLink $crmDealLink): void
32 {
33 $analyticsEvent = $this->getAnalyticsEvent(self::EVENT_LINK_CREATED)
34 ->setElement(self::LINK_CREATE_METHOD_CRM_SEND)
35 ;
36
37 $this->sendAnalytics($analyticsEvent, $crmDealLink);
38 }
39
40 public function sendMeetingCreated(Link\Joint\JointLink $link): void
41 {
42 $analyticsEvent = $this->getAnalyticsEvent(self::EVENT_MEETING_PLACED);
43
44 $this->sendAnalytics($analyticsEvent, $link);
45 }
46
47 public function sendChatCreated(Link\EventLink $eventLink, string $whoStarted): void
48 {
49 $analyticsEvent = $this->getAnalyticsEvent(self::EVENT_CHAT_STARTED)
50 ->setElement($whoStarted)
51 ;
52
53 $parentLink = (new Link\Factory())->getLinkByHash($eventLink->getParentLinkHash());
54
55 $this->sendAnalytics($analyticsEvent, $parentLink);
56 }
57
58 public function sendCallStarted(Link\Joint\JointLink $parentLink): void
59 {
60 $analyticsEvent = $this->getAnalyticsEvent(self::EVENT_CALL_STARTED);
61
62 $this->sendAnalytics($analyticsEvent, $parentLink);
63 }
64
65 protected function getAnalyticsEvent(string $eventName): AnalyticsEvent
66 {
67 return (new AnalyticsEvent($eventName, self::TOOL_CALENDAR, self::CATEGORY_SLOTS));
68 }
69
70 protected function sendAnalytics(AnalyticsEvent $analyticsEvent, ?Link\Joint\JointLink $link): void
71 {
72 $isJoint = false;
73 $members = [];
74 $rule = null;
75
76 if (!is_null($link))
77 {
78 $members = $link->getMembers();
79 $rule = $link->getSharingRule();
80 $isJoint = $link->isJoint();
81 }
82
83 $context = $link instanceof Link\CrmDealLink ? self::CONTEXT_CRM : self::CONTEXT_CALENDAR;
84 $type = $isJoint ? self::TYPE_MULTIPLE : self::TYPE_SOLO;
85 $membersCount = count($members) + 1;
86 $ruleChanges = (new Link\Rule\Mapper())->getChanges($rule);
87
88 $analyticsEvent
89 ->setSection($context)
90 ->setType($type)
91 ->setP1("peopleCount_$membersCount")
92 ->setP2("customDays_{$ruleChanges['customDays']}")
93 ->setP3("customLength_{$ruleChanges['customLength']}")
94 ->send()
95 ;
96 }
97}
sendChatCreated(Link\EventLink $eventLink, string $whoStarted)
Definition analytics.php:47
getAnalyticsEvent(string $eventName)
Definition analytics.php:65
sendCallStarted(Link\Joint\JointLink $parentLink)
Definition analytics.php:58
sendMeetingCreated(Link\Joint\JointLink $link)
Definition analytics.php:40
sendLinkSent(Link\CrmDealLink $crmDealLink)
Definition analytics.php:31
sendAnalytics(AnalyticsEvent $analyticsEvent, ?Link\Joint\JointLink $link)
Definition analytics.php:70