1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
event.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Seo\Conversion\Facebook;
4
5
6
use Bitrix\Seo\Conversion\ConversionEventInterface;
7
8
class
Event
implements
ConversionEventInterface
9
{
10
private
$container = [];
11
12
// action source values : https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event#action-source
13
public
const
ACTION_SOURCE_EMAIL
=
'email'
;
14
public
const
ACTION_SOURCE_WEBSITE
=
'website'
;
15
public
const
ACTION_SOURCE_APP
=
'app'
;
16
public
const
ACTION_SOURCE_PHONE_CALL
=
'phone_call'
;
17
public
const
ACTION_SOURCE_CHAT
=
'chat'
;
18
public
const
ACTION_SOURCE_PHYSICAL_STORE
=
'physical_store'
;
19
public
const
ACTION_SOURCE_SYSTEM_GENERATED
=
'system_generated'
;
20
public
const
ACTION_SOURCE_OTHER
=
'other'
;
21
22
// events description: https://developers.facebook.com/docs/facebook-pixel/reference#standard-events
23
public
const
EVENT_ADD_PAYMENT
=
'AddPaymentInfo'
;
24
public
const
EVENT_ADD_TO_CART
=
'AddToCart'
;
25
public
const
EVENT_ADD_TO_WISH_LIST
=
'AddToWishlist'
;
26
public
const
EVENT_COMPLETE_REGISTRATION
=
'CompleteRegistration'
;
27
public
const
EVENT_CONTACT
=
'Contact'
;
28
public
const
EVENT_DONATE
=
'CustomizeProduct'
;
29
public
const
EVENT_FIND_LOCATION
=
'FindLocation'
;
30
public
const
EVENT_INITIATE_CHECKOUT
=
'InitiateCheckout'
;
31
public
const
EVENT_LEAD
=
'Lead'
;
32
public
const
EVENT_PAGE_VIEW
=
'PageView'
;
33
public
const
EVENT_PURCHASE
=
'Purchase'
;
34
public
const
EVENT_SEARCH
=
'Search'
;
35
public
const
EVENT_START_TRIAL
=
'StartTrial'
;
36
public
const
EVENT_SUBMIT_APPLICATION
=
'SubmitApplication'
;
37
public
const
EVENT_SUBSCRIBE
=
'Subscribe'
;
38
public
const
EVENT_VIEW_CONTENT
=
'ViewContent'
;
39
40
private
function
setParameter(
string
$key
,$value)
41
{
42
$this->container[
$key
] = $value;
43
}
44
45
private
function
getParameter(
string
$key
)
46
{
47
return
array_key_exists(
$key
,$this->container)? $this->container[
$key
] :
null
;
48
}
49
50
public
static
function
getEventTypeList
()
51
{
52
return
[
53
static::EVENT_ADD_PAYMENT,
54
static::EVENT_ADD_TO_CART,
55
static::EVENT_ADD_TO_WISH_LIST,
56
static::EVENT_COMPLETE_REGISTRATION,
57
static::EVENT_CONTACT,
58
static::EVENT_DONATE,
59
static::EVENT_FIND_LOCATION,
60
static::EVENT_INITIATE_CHECKOUT,
61
static::EVENT_LEAD,
62
static::EVENT_PAGE_VIEW,
63
static::EVENT_SEARCH,
64
static::EVENT_START_TRIAL,
65
static::EVENT_SUBMIT_APPLICATION,
66
static::EVENT_SUBSCRIBE,
67
static::EVENT_VIEW_CONTENT,
68
static::EVENT_PURCHASE
69
];
70
}
71
75
public
static
function
getActionSourceList
()
76
{
77
return
[
78
static::ACTION_SOURCE_EMAIL,
79
static::ACTION_SOURCE_WEBSITE,
80
static::ACTION_SOURCE_APP,
81
static::ACTION_SOURCE_PHONE_CALL,
82
static::ACTION_SOURCE_CHAT,
83
static::ACTION_SOURCE_PHYSICAL_STORE,
84
static::ACTION_SOURCE_SYSTEM_GENERATED,
85
static::ACTION_SOURCE_OTHER
86
];
87
}
88
94
public
function
__construct
(?
array
$params
=
null
)
95
{
96
if
(
$params
&& !empty(
$params
))
97
{
98
if
(array_key_exists(
'action_source'
,
$params
) && is_string(
$params
[
'action_source'
]))
99
{
100
$this->
setActionSource
(
$params
[
'action_source'
]);
101
}
102
if
(array_key_exists(
'event_time'
,
$params
) && is_int(
$params
[
'event_time'
]))
103
{
104
$this->
setTime
(
$params
[
'event_time'
]);
105
}
106
if
(array_key_exists(
'opt_out'
,
$params
) && is_bool(
$params
[
'opt_out'
]))
107
{
108
$this->
setDynamicAdsOption
(
$params
[
'opt_out'
]);
109
}
110
if
(array_key_exists(
'event_name'
,
$params
) && is_string(
$params
[
'event_name'
]))
111
{
112
$this->
setEventType
(
$params
[
'event_name'
]);
113
}
114
if
(array_key_exists(
'event_source_url'
,
$params
) && is_string(
$params
[
'event_source_url'
]))
115
{
116
$this->
setSource
(
$params
[
'event_source_url'
]);
117
}
118
if
(array_key_exists(
'user_data'
,
$params
))
119
{
120
if
(
$params
[
'user_data'
] instanceof
UserData
)
121
{
122
$this->
setUserData
(
$params
[
'user_data'
]);
123
124
}
elseif
(is_array(
$params
[
'user_data'
]))
125
{
126
$this->
setUserData
(
new
UserData(
$params
[
'user_data'
]));
127
}
128
}
129
if
(array_key_exists(
'custom_data'
,
$params
))
130
{
131
if
(
$params
[
'custom_data'
] instanceof
CustomData
)
132
{
133
$this->
setCustomData
(
$params
[
'custom_data'
]);
134
135
}
elseif
(is_array(
$params
[
'custom_data'
]))
136
{
137
$this->
setCustomData
(
new
CustomData(
$params
[
'custom_data'
]));
138
}
139
}
140
}
141
142
if
(!$this->getParameter(
'event_time'
))
143
{
144
$this->setParameter(
'event_time'
,time());
145
}
146
147
}
148
155
public
function
setActionSource
(?
string
$action
= self::ACTION_SOURCE_WEBSITE)
156
{
157
if
(in_array(
$action
,static::getActionSourceList()))
158
{
159
$this->setParameter(
'action_source'
,
$action
);
160
}
161
return
$this;
162
}
163
170
public
function
setTime
(?
int
$timeStamp)
171
{
172
173
if
(is_int($timeStamp))
174
{
175
$this->setParameter(
'event_time'
,$timeStamp);
176
}
177
return
$this;
178
}
179
185
public
function
setDynamicAdsOption
(?
bool
$option
=
false
)
186
{
187
$this->setParameter(
'opt_out'
,
$option
);
188
return
$this;
189
}
190
197
public
function
setEventType
(
string
$type
)
198
{
199
//if(in_array($type,static::getEventTypeList()))
200
{
201
$this->setParameter(
'event_name'
,
$type
);
202
}
203
return
$this;
204
}
205
212
public
function
setSource
(
string
$source)
213
{
214
if
(preg_match(
'%^((https://)|(www\.)|(http://))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i'
,$source))
215
{
216
$this->setParameter(
'event_source_url'
,$source);
217
}
218
return
$this;
219
}
220
227
public
function
setUserData
(
UserData
$userData)
228
{
229
$this->setParameter(
'user_data'
,$userData);
230
return
$this;
231
}
232
239
public
function
setCustomData
(
CustomData
$data
)
240
{
241
$this->setParameter(
'custom_data'
,
$data
);
242
return
$this;
243
}
244
248
public
function
validate
() : bool
249
{
250
[$userData, $customData] = [$this->getParameter(
'user_data'
), $this->getParameter(
'custom_data'
)];
251
if
(
252
$this->getParameter(
'event_name'
)
253
&& $userData instanceof
UserData
254
&& $userData->
validate
()
255
&& $customData instanceof
CustomData
256
&& $customData->
validate
()
257
&& $this->getParameter(
'event_time'
)
258
&& $this->getParameter(
'event_time'
) + 604800 > time()
259
)
260
{
261
$result
=
true
;
262
if
($this->getParameter(
'event_name'
) === static::EVENT_PURCHASE)
263
{
264
$result
=
$result
&&
is_set
($customData->getValue()) &&
is_set
($customData->getCurrency());
265
}
266
if
($this->getParameter(
'action_source'
) === static::ACTION_SOURCE_WEBSITE)
267
{
268
$result
=
is_set
($this->getParameter(
'event_source_url'
));
269
}
270
return
$result
;
271
}
272
return
false
;
273
}
274
278
public
function
prepareData
() :
array
279
{
280
[$userData, $customData] = [$this->getParameter(
'user_data'
), $this->getParameter(
'custom_data'
)];
281
return
array_filter([
282
'action_source'
=> $this->getParameter(
'action_source'
),
283
'custom_data'
=> $customData->toArray(),
284
'user_data'
=> $userData->toArray(),
285
'event_source_url'
=> $this->getParameter(
'event_source_url'
),
286
'event_name'
=> $this->getParameter(
'event_name'
),
287
'opt_out'
=> $this->getParameter(
'opt_out'
),
288
'event_time'
=> $this->getParameter(
'event_time'
)
289
]);
290
}
291
}
$type
$type
Определения
options.php:106
Bitrix\Seo\Conversion\Facebook\CustomData
Определения
customdata.php:11
Bitrix\Seo\Conversion\Facebook\CustomData\validate
validate()
Определения
customdata.php:246
Bitrix\Seo\Conversion\Facebook\Event
Определения
event.php:9
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_CHAT
const ACTION_SOURCE_CHAT
Определения
event.php:17
Bitrix\Seo\Conversion\Facebook\Event\EVENT_COMPLETE_REGISTRATION
const EVENT_COMPLETE_REGISTRATION
Определения
event.php:26
Bitrix\Seo\Conversion\Facebook\Event\EVENT_FIND_LOCATION
const EVENT_FIND_LOCATION
Определения
event.php:29
Bitrix\Seo\Conversion\Facebook\Event\EVENT_VIEW_CONTENT
const EVENT_VIEW_CONTENT
Определения
event.php:38
Bitrix\Seo\Conversion\Facebook\Event\EVENT_SEARCH
const EVENT_SEARCH
Определения
event.php:34
Bitrix\Seo\Conversion\Facebook\Event\validate
validate()
Определения
event.php:248
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_OTHER
const ACTION_SOURCE_OTHER
Определения
event.php:20
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_SYSTEM_GENERATED
const ACTION_SOURCE_SYSTEM_GENERATED
Определения
event.php:19
Bitrix\Seo\Conversion\Facebook\Event\EVENT_CONTACT
const EVENT_CONTACT
Определения
event.php:27
Bitrix\Seo\Conversion\Facebook\Event\EVENT_PAGE_VIEW
const EVENT_PAGE_VIEW
Определения
event.php:32
Bitrix\Seo\Conversion\Facebook\Event\setTime
setTime(?int $timeStamp)
Определения
event.php:170
Bitrix\Seo\Conversion\Facebook\Event\prepareData
prepareData()
Определения
event.php:278
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_PHYSICAL_STORE
const ACTION_SOURCE_PHYSICAL_STORE
Определения
event.php:18
Bitrix\Seo\Conversion\Facebook\Event\EVENT_DONATE
const EVENT_DONATE
Определения
event.php:28
Bitrix\Seo\Conversion\Facebook\Event\getActionSourceList
static getActionSourceList()
Определения
event.php:75
Bitrix\Seo\Conversion\Facebook\Event\EVENT_INITIATE_CHECKOUT
const EVENT_INITIATE_CHECKOUT
Определения
event.php:30
Bitrix\Seo\Conversion\Facebook\Event\EVENT_SUBMIT_APPLICATION
const EVENT_SUBMIT_APPLICATION
Определения
event.php:36
Bitrix\Seo\Conversion\Facebook\Event\EVENT_ADD_TO_WISH_LIST
const EVENT_ADD_TO_WISH_LIST
Определения
event.php:25
Bitrix\Seo\Conversion\Facebook\Event\EVENT_LEAD
const EVENT_LEAD
Определения
event.php:31
Bitrix\Seo\Conversion\Facebook\Event\getEventTypeList
static getEventTypeList()
Определения
event.php:50
Bitrix\Seo\Conversion\Facebook\Event\EVENT_PURCHASE
const EVENT_PURCHASE
Определения
event.php:33
Bitrix\Seo\Conversion\Facebook\Event\EVENT_SUBSCRIBE
const EVENT_SUBSCRIBE
Определения
event.php:37
Bitrix\Seo\Conversion\Facebook\Event\setDynamicAdsOption
setDynamicAdsOption(?bool $option=false)
Определения
event.php:185
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_WEBSITE
const ACTION_SOURCE_WEBSITE
Определения
event.php:14
Bitrix\Seo\Conversion\Facebook\Event\setUserData
setUserData(UserData $userData)
Определения
event.php:227
Bitrix\Seo\Conversion\Facebook\Event\setSource
setSource(string $source)
Определения
event.php:212
Bitrix\Seo\Conversion\Facebook\Event\__construct
__construct(?array $params=null)
Определения
event.php:94
Bitrix\Seo\Conversion\Facebook\Event\setActionSource
setActionSource(?string $action=self::ACTION_SOURCE_WEBSITE)
Определения
event.php:155
Bitrix\Seo\Conversion\Facebook\Event\EVENT_ADD_TO_CART
const EVENT_ADD_TO_CART
Определения
event.php:24
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_APP
const ACTION_SOURCE_APP
Определения
event.php:15
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_PHONE_CALL
const ACTION_SOURCE_PHONE_CALL
Определения
event.php:16
Bitrix\Seo\Conversion\Facebook\Event\EVENT_START_TRIAL
const EVENT_START_TRIAL
Определения
event.php:35
Bitrix\Seo\Conversion\Facebook\Event\setCustomData
setCustomData(CustomData $data)
Определения
event.php:239
Bitrix\Seo\Conversion\Facebook\Event\EVENT_ADD_PAYMENT
const EVENT_ADD_PAYMENT
Определения
event.php:23
Bitrix\Seo\Conversion\Facebook\Event\ACTION_SOURCE_EMAIL
const ACTION_SOURCE_EMAIL
Определения
event.php:13
Bitrix\Seo\Conversion\Facebook\Event\setEventType
setEventType(string $type)
Определения
event.php:197
Bitrix\Seo\Conversion\Facebook\UserData
Определения
userdata.php:8
Bitrix\Seo\Conversion\Facebook\UserData\validate
validate()
Определения
userdata.php:288
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
Bitrix\Seo\Conversion\ConversionEventInterface
Определения
conversioneventinterface.php:6
is_set
is_set($a, $k=false)
Определения
tools.php:2133
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$option
$option
Определения
options.php:1711
$action
$action
Определения
file_dialog.php:21
bitrix
modules
seo
lib
conversion
facebook
event.php
Создано системой
1.14.0