Skip to content

Commit 4dee39c

Browse files
authored
Add support for anonymous users (slashequip#22)
* Add support for anonymous users * clean * start Cursor support. * improve actions * attempt to fix actions * Update docs
1 parent d05aa7d commit 4dee39c

20 files changed

+265
-111
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
description: Rules for placing and organizing Cursor rule files in the repository.
3+
globs: *.mdc
4+
---
5+
# Cursor Rules Location
6+
7+
Rules for placing and organizing Cursor rule files in the repository.
8+
9+
<rule>
10+
name: cursor_rules_location
11+
description: Standards for placing Cursor rule files in the correct directory
12+
filters:
13+
# Match any .mdc files
14+
- type: file_extension
15+
pattern: "\\.mdc$"
16+
# Match files that look like Cursor rules
17+
- type: content
18+
pattern: "(?s)<rule>.*?</rule>"
19+
# Match file creation events
20+
- type: event
21+
pattern: "file_create"
22+
23+
actions:
24+
- type: reject
25+
conditions:
26+
- pattern: "^(?!\\.\\/\\.cursor\\/rules\\/.*\\.mdc$)"
27+
message: "Cursor rule files (.mdc) must be placed in the .cursor/rules directory"
28+
29+
- type: suggest
30+
message: |
31+
When creating Cursor rules:
32+
33+
1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
34+
```
35+
.cursor/rules/
36+
├── your-rule-name.mdc
37+
├── another-rule.mdc
38+
└── ...
39+
```
40+
41+
2. Follow the naming convention:
42+
- Use kebab-case for filenames
43+
- Always use .mdc extension
44+
- Make names descriptive of the rule's purpose
45+
46+
3. Directory structure:
47+
```
48+
PROJECT_ROOT/
49+
├── .cursor/
50+
│ └── rules/
51+
│ ├── your-rule-name.mdc
52+
│ └── ...
53+
└── ...
54+
```
55+
56+
4. Never place rule files:
57+
- In the project root
58+
- In subdirectories outside .cursor/rules
59+
- In any other location
60+
61+
examples:
62+
- input: |
63+
# Bad: Rule file in wrong location
64+
rules/my-rule.mdc
65+
my-rule.mdc
66+
.rules/my-rule.mdc
67+
68+
# Good: Rule file in correct location
69+
.cursor/rules/my-rule.mdc
70+
output: "Correctly placed Cursor rule file"
71+
72+
metadata:
73+
priority: high
74+
version: 1.0
75+
</rule>

.github/workflows/code-style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Code Style
22

3-
on: [push]
3+
on: [pull_request]
44

55
jobs:
66
code-style:
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup PHP
1414
uses: shivammathur/setup-php@v2
1515
with:
16-
php-version: '8.1'
16+
php-version: '8.2'
1717
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
1818
coverage: none
1919

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: run-tests
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
jobs:
66
test:
@@ -9,9 +9,9 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [8.3]
12+
php: ['8.2','8.3', '8.4']
1313
laravel: [11.*]
14-
stability: [prefer-stable]
14+
stability: ['prefer-stable']
1515
include:
1616
- laravel: 11.*
1717
testbench: 9.*

.github/workflows/static-analysis.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
name: Static Analysis
22

3-
on:
4-
push:
5-
paths:
6-
- '**.php'
7-
- 'phpstan.neon.dist'
3+
on: [pull_request]
84

95
jobs:
10-
psalm:
6+
phpstan:
117
name: static-analysis
128
runs-on: ubuntu-latest
139
steps:
@@ -16,7 +12,7 @@ jobs:
1612
- name: Setup PHP
1713
uses: shivammathur/setup-php@v2
1814
with:
19-
php-version: '8.1'
15+
php-version: '8.2'
2016
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
2117
coverage: none
2218

.php_cs.dist

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

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,29 @@ Segment::identifyNow('User Signed Up', [
170170
]);
171171
```
172172

173+
### Anonymous users
174+
175+
Segment allows you to track events for users that are not yet users in your system, they call these anonymous users.
176+
177+
To track events for anonymous users you can use apply the `ShouldBeAnonymouslyIdentified` interface to any `CanBeIdentifiedForSegment` implementation.
178+
179+
```php
180+
use SlashEquip\LaravelSegment\Contracts\CanBeIdentifiedForSegment;
181+
use SlashEquip\LaravelSegment\Contracts\ShouldBeAnonymouslyIdentified;
182+
183+
class SegmentAnonymousTestUser implements CanBeIdentifiedForSegment, ShouldBeAnonymouslyIdentified
184+
{
185+
}
186+
```
187+
188+
For convenience, the package comes with a `SimpleSegmentAnonymousUser` class that implements the `ShouldBeAnonymouslyIdentified` interface.
189+
190+
```php
191+
use SlashEquip\LaravelSegment\SimpleSegmentAnonymousUser;
192+
193+
Segment::forUser(new SimpleSegmentAnonymousUser('123'))->track('Kitchen sink used');
194+
```
195+
173196
### Laravel Notifications
174197
This package includes an out-of-the-box notification channel, to allow you to use Laravel's built-in notification
175198
feature. To send Segment events to users as notifications, generate your notification as normal;

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^8.1",
17+
"php": "^8.2",
1818
"guzzlehttp/guzzle": "^7.8",
19-
"illuminate/contracts": "^9.0|^10.0|^11.0"
19+
"illuminate/contracts": "^10.0|^11.0"
2020
},
2121
"require-dev": {
2222
"laravel/pint": "^1.18",
2323
"mockery/mockery": "^1.6",
2424
"nunomaduro/larastan": "^2.0",
25-
"orchestra/testbench": "^7.25|^8.5|^9.0",
26-
"pestphp/pest": "^2.36",
27-
"vimeo/psalm": "^5.26"
25+
"orchestra/testbench": "^8.5|^9.0",
26+
"pestphp/pest": "^2.36"
2827
},
2928
"autoload": {
3029
"psr-4": {

psalm.xml.dist

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

src/Contracts/SegmentServiceContract.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function identify(?array $identifyData = null): void;
3333
*/
3434
public function identifyNow(?array $identifyData = null): void;
3535

36-
3736
public function forUser(CanBeIdentifiedForSegment $user): PendingUserSegment;
3837

3938
public function push(CanBeSentToSegment $segment): void;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace SlashEquip\LaravelSegment\Contracts;
4+
5+
interface ShouldBeAnonymouslyIdentified {}

0 commit comments

Comments
 (0)