6
6
7
7
use Magento \Framework \App \Action \HttpPostActionInterface ;
8
8
use Magento \Framework \App \RequestInterface ;
9
+ use Meta \Conversion \Helper \ServerSideHelper ;
10
+ use Meta \Conversion \Helper \ServerEventFactory ;
9
11
use Meta \BusinessExtension \Helper \FBEHelper ;
10
12
use Magento \Framework \Controller \Result \JsonFactory ;
11
13
use Magento \Framework \Controller \Result \Json ;
12
- use Magento \Framework \MessageQueue \PublisherInterface ;
13
- use Magento \Framework \Serialize \Serializer \Json as JsonSerializer ;
14
14
15
15
class Tracker implements HttpPostActionInterface
16
16
{
@@ -19,6 +19,11 @@ class Tracker implements HttpPostActionInterface
19
19
*/
20
20
private $ request ;
21
21
22
+ /**
23
+ * @var ServerSideHelper
24
+ */
25
+ private $ serverSideHelper ;
26
+
22
27
/**
23
28
* @var FBEHelper
24
29
*/
@@ -35,36 +40,33 @@ class Tracker implements HttpPostActionInterface
35
40
private $ jsonFactory ;
36
41
37
42
/**
38
- * @var PublisherInterface
43
+ * @var ServerEventFactory
39
44
*/
40
- private $ publisher ;
41
-
42
- /**
43
- * @var JsonSerializer
44
- */
45
- private $ jsonSerializer ;
45
+ private $ serverEventFactory ;
46
46
47
47
/**
48
+ * Constructor
49
+ *
48
50
* @param RequestInterface $request
51
+ * @param ServerSideHelper $serverSideHelper
49
52
* @param FBEHelper $fbeHelper
50
53
* @param JsonFactory $jsonFactory
51
- * @param PublisherInterface $publisher
52
- * @param JsonSerializer $jsonSerializer
54
+ * @param ServerEventFactory $serverEventFactory
53
55
* @param array $pixelEvents
54
56
*/
55
57
public function __construct (
56
58
RequestInterface $ request ,
59
+ ServerSideHelper $ serverSideHelper ,
57
60
FBEHelper $ fbeHelper ,
58
61
JsonFactory $ jsonFactory ,
59
- PublisherInterface $ publisher ,
60
- JsonSerializer $ jsonSerializer ,
62
+ ServerEventFactory $ serverEventFactory ,
61
63
array $ pixelEvents = []
62
64
) {
63
65
$ this ->request = $ request ;
66
+ $ this ->serverSideHelper = $ serverSideHelper ;
64
67
$ this ->fbeHelper = $ fbeHelper ;
65
68
$ this ->jsonFactory = $ jsonFactory ;
66
- $ this ->publisher = $ publisher ;
67
- $ this ->jsonSerializer = $ jsonSerializer ;
69
+ $ this ->serverEventFactory = $ serverEventFactory ;
68
70
$ this ->pixelEvents = $ pixelEvents ;
69
71
}
70
72
@@ -79,13 +81,22 @@ public function execute(): Json
79
81
try {
80
82
$ params = $ this ->request ->getParams ();
81
83
$ eventName = $ params ['eventName ' ];
84
+ $ eventId = $ params ['eventId ' ];
82
85
83
86
if ($ eventName ) {
84
87
$ payload = $ this ->pixelEvents [$ eventName ]->getPayload ($ params );
85
- $ payload ['event_id ' ] = $ params ['eventId ' ];
86
- $ payload ['event_type ' ] = $ this ->pixelEvents [$ eventName ]->getEventType ();
87
88
if (isset ($ payload )) {
88
- $ this ->publisher ->publish ('send.conversion.event.to.meta ' , $ this ->jsonSerializer ->serialize ($ payload ));
89
+ // Add source and pluginVersion in the payload as custom properties
90
+ $ payload ['custom_properties ' ] = [];
91
+ $ payload ['custom_properties ' ]['source ' ] = $ this ->fbeHelper ->getSource ();
92
+ $ payload ['custom_properties ' ]['pluginVersion ' ] = $ this ->fbeHelper ->getPluginVersion ();
93
+ $ eventType = $ this ->pixelEvents [$ eventName ]->getEventType ();
94
+ $ event = $ this ->serverEventFactory ->createEvent ($ eventType , array_filter ($ payload ), $ eventId );
95
+ if (isset ($ payload ['userDataFromOrder ' ])) {
96
+ $ this ->serverSideHelper ->sendEvent ($ event , $ payload ['userDataFromOrder ' ]);
97
+ } else {
98
+ $ this ->serverSideHelper ->sendEvent ($ event );
99
+ }
89
100
$ response ['success ' ] = true ;
90
101
}
91
102
}
0 commit comments