Skip to content

Commit 4287812

Browse files
committed
Add custom properties
1 parent 55c8147 commit 4287812

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/Event/Custom.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@ final class Custom extends Parameters
3434

3535
public ?float $value = null;
3636

37+
/**
38+
* This holds an array of custom properties. See https://developers.facebook.com/docs/meta-pixel/implementation/conversion-tracking#custom-properties
39+
*
40+
* NOTICE that if you define a custom property with the same name as any of the standard properties, your
41+
* custom property will be overridden by the value of the standard property
42+
*
43+
* @var array<string, mixed>
44+
*/
45+
public array $customProperties = [];
46+
3747
protected function getMapping(): array
3848
{
39-
return [
49+
return array_merge($this->customProperties, [
4050
'content_category' => $this->contentCategory,
4151
'content_ids' => $this->contentIds,
4252
'content_name' => $this->contentName,
@@ -50,7 +60,7 @@ protected function getMapping(): array
5060
'search_string' => $this->searchString,
5161
'status' => $this->status,
5262
'value' => $this->value,
53-
];
63+
]);
5464
}
5565

5666
/**

tests/Event/CustomTest.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\MetaConversionsApi\Event;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* @covers \Setono\MetaConversionsApi\Event\Custom
11+
*/
12+
final class CustomTest extends TestCase
13+
{
14+
/**
15+
* @test
16+
*/
17+
public function it_generates_payload(): void
18+
{
19+
$user = new Custom();
20+
$user->currency = 'DKK';
21+
$user->customProperties['my_custom_property'] = 'test';
22+
23+
self::assertEquals([
24+
'currency' => 'dkk',
25+
'my_custom_property' => 'test',
26+
], $user->getPayload());
27+
}
28+
}

0 commit comments

Comments
 (0)