Skip to content

Commit bd06962

Browse files
spam-n-eggsCopilot
andauthored
Adding additional fields (#3)
* Added 'Additional Fields' to User Object for Identify calls. * Added additionalFields to Tracking Event too * Updated Keywords * Update src/User.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/TrackingEvent.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix styling * Fixed composer installation. * Deconflicting pest-plugin-faker * Fix failing tests. * Fixed phpstan so it runs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 0f1c7c7 commit bd06962

File tree

8 files changed

+20
-54
lines changed

8 files changed

+20
-54
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Dominion Solutions LLC <mark.horninger@dominion.solutions>
3+
Copyright (c) Dominion Solutions LLC <sales@dominion.solutions>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "dominion-solutions/customerio",
33
"description": "A Laravel Integration Layer for CustomerIO",
44
"keywords": [
5-
"Dominion Solutions LLC",
65
"laravel",
7-
"customerio"
6+
"customerio",
7+
"tracking"
88
],
99
"homepage": "https://github.com/dominion-solutions/customerio",
1010
"license": "MIT",
@@ -23,15 +23,15 @@
2323
"spatie/laravel-package-tools": "^1.16"
2424
},
2525
"require-dev": {
26-
"illuminate/http": "*",
26+
"illuminate/http": "^10.0||^11.0||^12.0",
2727
"larastan/larastan": "^2.9||^3.0",
2828
"laravel/pint": "^1.14",
2929
"matthewbdaly/artisan-standalone": "^0.0.12",
3030
"nunomaduro/collision": "^8.1.1||^7.10.0",
3131
"orchestra/testbench": "^10.0.0||^9.0.0||^8.22.0",
3232
"pestphp/pest": "^2.0||^3.0",
3333
"pestphp/pest-plugin-arch": "^2.5||^3.0",
34-
"pestphp/pest-plugin-faker": "^3.0",
34+
"pestphp/pest-plugin-faker": "^2.0||^3.0",
3535
"pestphp/pest-plugin-laravel": "^2.0||^3.0",
3636
"phpstan/extension-installer": "^1.3",
3737
"phpstan/phpstan-deprecation-rules": "^1.1||^2.0",

database/factories/ModelFactory.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

database/migrations/create_customerio_table.php.stub

Lines changed: 0 additions & 19 deletions
This file was deleted.

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ parameters:
66
paths:
77
- src
88
- config
9-
- database
109
tmpDir: build/phpstan
1110
checkOctaneCompatibility: true
1211
checkModelProperties: true

src/TrackingEvent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ public function __construct(
1010
public ?string $userId = null,
1111
public ?string $event = null,
1212
public ?array $properties = [],
13+
public array $additionalFields = [],
1314
public ?array $context = [],
1415
) {}
1516

1617
public function toArray(): array
1718
{
18-
return [
19+
return collect([
1920
'userId' => $this->userId,
2021
'event' => $this->event,
2122
'properties' => $this->properties,
2223
'context' => $this->context,
23-
];
24+
])->merge($this->additionalFields)->toArray();
2425
}
2526
}

src/User.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66

77
class User implements Arrayable
88
{
9-
public function __construct(public ?string $userId = null,
9+
public function __construct(
10+
public ?string $userId = null,
1011
public ?string $anonymousId = null,
11-
public array $traits = []
12+
public array $additionalFields = [],
13+
public ?array $traits = [],
1214
) {}
1315

14-
public function toArray()
16+
public function toArray(): array
1517
{
16-
return [
18+
$baseData = collect([
1719
'userId' => $this->userId,
1820
'anonymousId' => $this->anonymousId,
1921
'traits' => $this->traits,
20-
];
22+
]);
23+
24+
return $baseData->merge($this->additionalFields)->toArray();
2125
}
2226
}

tests/Unit/TrackingEventTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
it('can create a tracking event', function () {
77
mockCustomerIO();
8-
$trackingEvent = new TrackingEvent(userId: fake()->email(), tags: [
8+
$trackingEvent = new TrackingEvent(userId: fake()->email(), properties: [
99
fake()->word() => fake()->word(),
1010
]);
1111
$response = CustomerIO::trackEvent($trackingEvent);
@@ -14,7 +14,7 @@
1414

1515
it('can create an anonymous tracking event', function () {
1616
mockCustomerIO();
17-
$trackingEvent = new TrackingEvent(anonymousId: fake()->email(), tags: [
17+
$trackingEvent = new TrackingEvent(userId: fake()->email(), properties: [
1818
fake()->word() => fake()->word(),
1919
]);
2020
$response = CustomerIO::trackEvent($trackingEvent);
@@ -23,7 +23,7 @@
2323

2424
it('can handle errors', function () {
2525
mockCustomerIO(trackSuccess: false);
26-
$trackingEvent = new TrackingEvent(userId: fake()->email(), tags: [
26+
$trackingEvent = new TrackingEvent(userId: fake()->email(), properties: [
2727
fake()->word() => fake()->word(),
2828
]);
2929
$response = CustomerIO::trackEvent($trackingEvent);

0 commit comments

Comments
 (0)