Skip to content

Commit

Permalink
Merge pull request #16 from RomulusED69/feat/Issue-15
Browse files Browse the repository at this point in the history
fix(profile): prefer using MixPanel reserved properties for User profiles
  • Loading branch information
gordalina committed Sep 22, 2020
2 parents 43ff6d2 + 72d481d commit a211caa
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 17 deletions.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
## [v3.2.0](https://github.com/gordalina/GordalinaMixpanelBundle/releases/tag/3.1.0)

[3.1.0...3.2.0](https://github.com/gordalina/GordalinaMixpanelBundle/compare/3.1.0...3.2.0)

### Features

- Used `Profile properties`. [#16](https://github.com/gordalina/GordalinaMixpanelBundle/pull/16) by @RomulusED69

### Deprecations

- In your config file replace

```yaml
Symfony\Component\Security\Core\User\UserInterface:
id: username
email: email
App\Entity\User:
id: id
first_name: first_name
last_name: last_name
email: email
phone: phone
```
By
```yaml
Symfony\Component\Security\Core\User\UserInterface:
id: username
$email: email
App\Entity\User:
id: id
$first_name: first_name
$last_name: last_name
$email: email
$phone: phone
```

## [v3.1.0](https://github.com/gordalina/GordalinaMixpanelBundle/releases/tag/3.1.0)

[3.0.0...3.1.0](https://github.com/gordalina/GordalinaMixpanelBundle/compare/3.0.0...3.1.0)
Expand Down
46 changes: 42 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Gordalina\MixpanelBundle\DependencyInjection;

use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand Down Expand Up @@ -69,13 +70,34 @@ public function getConfigTreeBuilder()
->then(function ($v) {
return ['id' => $v];
})
->ifTrue(function ($keys) {
foreach ($keys as $key => $value) {
if (isset($keys['$'.$key])) {
return true;
}
}
return false;
})
->thenInvalid('Duplicated property found in %s. If this variable is a MixPanel reserved property, please prefix it by "$".')
->end()
->children()
->scalarNode('id')->isRequired()->end()
->scalarNode('first_name')->end()
->scalarNode('last_name')->end()
->scalarNode('email')->end()
->scalarNode('phone')->end()
->scalarNode('first_name')
->setDeprecated(...$this->getDeprecationParams('The "%node%" option at path "%path%" is deprecated. Use "$first_name" instead.'))
->end()
->scalarNode('$first_name')->end()
->scalarNode('last_name')
->setDeprecated(...$this->getDeprecationParams('The "%node%" option at path "%path%" is deprecated. Use "$last_name" instead.'))
->end()
->scalarNode('$last_name')->end()
->scalarNode('email')
->setDeprecated(...$this->getDeprecationParams('The "%node%" option at path "%path%" is deprecated. Use "$email" instead.'))
->end()
->scalarNode('$email')->end()
->scalarNode('phone')
->setDeprecated(...$this->getDeprecationParams('The "%node%" option at path "%path%" is deprecated. Use "$phone" instead.'))
->end()
->scalarNode('$phone')->end()
->arrayNode('extra_data')
->info('Non-default properties in Mixpanel user profile')
->prototype('array')
Expand Down Expand Up @@ -153,4 +175,20 @@ public function addMixpanelOptionsNode()

return $node;
}

/**
* @return array<int,string>
*/
private function getDeprecationParams(string $message): array
{
if (method_exists(BaseNode::class, 'getDeprecation')) {
return [
'gordalina/mixpanel-bundle',
'3.2',
$message,
];
}

return [$message];
}
}
2 changes: 1 addition & 1 deletion Mixpanel/Security/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getId($instance = null)

/**
* @param object $instance
* @param string $property id|first_name|last_name|email|phone
* @param string $property id|'$first_name'|'$last_name'|'$email'|'$phone'
*
* @return mixed
*/
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ gordalina_mixpanel:
users:
Symfony\Component\Security\Core\User\UserInterface:
id: username
email: email
$email: email

# All possible properties
YourAppBundle\Entity\User:
id: id
first_name: first_name
last_name: last_name
email: email
phone: phone
$first_name: first_name
$last_name: last_name
$email: email
$phone: phone
extra_data:
- { key: whatever, value: test }
```
Expand Down Expand Up @@ -193,14 +193,14 @@ class OrderController
**Events**
- `@Mixpanel\Register(prop="visits", value=3)`
- `@Mixpanel\Track(event="name", props={ "firstTime": true })`
- `@Mixpanel\Unregister(prop="email")`
- `@Mixpanel\Unregister(prop="$email")`

**Engagement**
- `@Mixpanel\Append(id=324, prop="fruits", value="apples" [, ignoreTime=false])`
- `@Mixpanel\ClearCharges(id=324 [, ignoreTime=false])`
- `@Mixpanel\DeleteUser(id=324 [, ignoreTime=false])`
- `@Mixpanel\Increment(id=324, prop="visits", value=3 [, ignoreTime=false])`
- `@Mixpanel\Remove(id=324, prop="email")`
- `@Mixpanel\Remove(id=324, prop="$email")`
- `@Mixpanel\Set(id=324, props={ "firstTime": true } [, ignoreTime=false])`
- `@Mixpanel\SetOnce(id=324, props={ "firstTime": true } [, ignoreTime=false])`
- `@Mixpanel\TrackCharge(id=697, amount="20.0" [, ignoreTime=false])`
Expand Down Expand Up @@ -369,15 +369,15 @@ gordalina_mixpanel:
users:
Symfony\Component\Security\Core\User\UserInterface:
id: username
email: email
$email: email

# All possible properties
YourAppBundle\Entity\User:
id: id
first_name: first_name
last_name: last_name
email: email
phone: phone
$first_name: first_name
$last_name: last_name
$email: email
$phone: phone
```

Spec
Expand Down

0 comments on commit a211caa

Please sign in to comment.