Skip to content

Commit e0fb35a

Browse files
committed
Allow empty array for user data
1 parent ea7ad81 commit e0fb35a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Generator/FbqGenerator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public function __construct()
2121

2222
public function generateInit(
2323
array $pixels,
24-
array $userData,
24+
array $userData = [],
2525
bool $includePageView = true,
2626
bool $includeScriptTag = true
2727
): string {
2828
try {
29-
$json = json_encode($userData, \JSON_THROW_ON_ERROR);
29+
$json = [] !== $userData ? json_encode($userData, \JSON_THROW_ON_ERROR) : null;
3030
} catch (\JsonException $e) {
3131
$this->logger->error($e->getMessage());
3232

@@ -36,7 +36,7 @@ public function generateInit(
3636
$str = '';
3737

3838
foreach ($pixels as $pixel) {
39-
$str .= sprintf("fbq('init', '%s', %s);", $pixel->id, $json);
39+
$str .= null === $json ? sprintf("fbq('init', '%s');", $pixel->id) : sprintf("fbq('init', '%s', %s);", $pixel->id, $json);
4040
}
4141

4242
if ($includePageView) {

src/Generator/FbqGeneratorInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface FbqGeneratorInterface
1616
*/
1717
public function generateInit(
1818
array $pixels,
19-
array $userData,
19+
array $userData = [],
2020
bool $includePageView = true,
2121
bool $includeScriptTag = true
2222
): string;

0 commit comments

Comments
 (0)