Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Apr 12, 2019
1 parent 5278745 commit b54ddda
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 3 deletions.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,76 @@ $ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate
```

### Step 6: Create a property
When you create a property in Google Analytics you receive a tracking id which looks something like UA-12345678-1.

Now create a new property in your Sylius shop by navigating to `/admin/properties/new`.
Remember to enable the property and enable the channels you want to track.

### Step 7: You're ready!
The events that are tracked are located in the [EventListener folder](src/EventListener).
To make your tracking even better you should create event listeners listening to the
builder events fired in i.e. the [PurchaseSubscriber](src/EventListener/PurchaseSubscriber.php).

Let's say you use the [Brand plugin](https://github.com/loevgaard/SyliusBrandPlugin) and want to enrich the items
tracked with the brand of the product. That would look like this:

```php
<?php

declare(strict_types=1);

namespace App\EventListener;

use Loevgaard\SyliusBrandPlugin\Model\BrandAwareInterface;
use Setono\SyliusAnalyticsPlugin\Builder\ItemBuilder;
use Setono\SyliusAnalyticsPlugin\Event\BuilderEvent;
use Sylius\Component\Core\Model\OrderItemInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;


final class AddBrandSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'setono_sylius_analytics.builder.item' => [
'addBrand',
],
];
}

public function addBrand(BuilderEvent $event): void
{
$builder = $event->getBuilder();
if(!$builder instanceof ItemBuilder) {
return;
}

$subject = $event->getSubject();

if(!$subject instanceof OrderItemInterface) {
return;
}

$product = $subject->getProduct();
if(!$product instanceof BrandAwareInterface) {
return;
}

$builder->setBrand($product->getBrand()->getName());
}
}

```

## Contribute
Ways you can contribute:
* Translate [messages](src/Resources/translations/messages.en.yaml) and [validators](src/Resources/translations/validators.en.yaml) to your mother tongue
* Create Behat tests that verifies the scripts are outputted on the respective pages
* Create new event subscribers that handle Analytics events which are not implemented

Thank you!

[ico-version]: https://poser.pugx.org/setono/sylius-analytics-plugin/v/stable
[ico-unstable-version]: https://poser.pugx.org/setono/sylius-analytics-plugin/v/unstable
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"friends-of-behat/symfony-extension": "^2.0",
"friends-of-behat/variadic-extension": "^1.1",
"lakion/mink-debug-extension": "^1.2.3",
"loevgaard/sylius-brand-plugin": "^2.0@beta",
"phpspec/phpspec": "^5.0",
"phpstan/phpstan-doctrine": "^0.10",
"phpstan/phpstan-shim": "^0.10",
Expand Down
3 changes: 0 additions & 3 deletions src/Doctrine/ORM/PropertyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

class PropertyRepository extends EntityRepository implements PropertyRepositoryInterface
{
/**
* {@inheritdoc}
*/
public function findByChannel(ChannelInterface $channel): array
{
return $this->createQueryBuilder('o')
Expand Down

0 comments on commit b54ddda

Please sign in to comment.