Skip to content

Commit af9f3a9

Browse files
[WIP] Converted: Tracking to server side
1 parent 56e6e37 commit af9f3a9

File tree

100 files changed

+2285
-927
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2285
-927
lines changed

.phpstorm.meta.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
namespace PHPSTORM_META;

README.md

+29-16
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@ Track user behavior in Facebook.
1212

1313
### Step 1: Download the plugin
1414

15-
This plugin uses the [TagBagBundle](https://github.com/Setono/TagBagBundle) to inject scripts onto your page.
16-
1715
Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:
1816

1917
```bash
2018
$ composer require setono/sylius-facebook-plugin
2119

22-
# Omit this line if you want to override layout.html.twig as described at https://github.com/Setono/TagBagBundle#usage
23-
$ composer require setono/sylius-tag-bag-plugin
24-
2520
```
2621

2722
This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation.
2823

29-
3024
### Step 2: Enable the plugin
3125

3226
Then, enable the plugin by adding it to the list of registered plugins/bundles
@@ -35,11 +29,8 @@ in `config/bundles.php` file of your project before (!) `SyliusGridBundle`:
3529
```php
3630
<?php
3731
$bundles = [
38-
Setono\TagBagBundle\SetonoTagBagBundle::class => ['all' => true],
39-
40-
// Omit this line if you didn't install the SyliusTagBagPlugin in step 1
41-
Setono\SyliusTagBagPlugin\SetonoSyliusTagBagPlugin::class => ['all' => true],
42-
32+
Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
33+
Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
4334
Setono\SyliusFacebookPlugin\SetonoSyliusFacebookPlugin::class => ['all' => true],
4435
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
4536
];
@@ -48,18 +39,26 @@ $bundles = [
4839
### Step 3: Configure plugin
4940

5041
```yaml
51-
# config/packages/_sylius.yaml
42+
# config/packages/setono_sylius_facebook.yaml
5243
imports:
53-
# ...
5444
- { resource: "@SetonoSyliusFacebookPlugin/Resources/config/app/config.yaml" }
55-
# ...
45+
46+
setono_sylius_facebook:
47+
access_token: '%env(FACEBOOK_ACCESS_TOKEN)%'
48+
```
49+
50+
```dotenv
51+
# .env
52+
###> setono/sylius-facebook-plugin ###
53+
FACEBOOK_ACCESS_TOKEN=<YOUR TOKEN>
54+
###< setono/sylius-facebook-plugin ###
5655
```
5756

5857
### Step 4: Import routing
5958

6059
```yaml
6160
# config/routes/setono_sylius_facebook.yaml
62-
setono_facebook_tracking:
61+
setono_sylius_facebook:
6362
resource: "@SetonoSyliusFacebookPlugin/Resources/config/routing.yaml"
6463
```
6564
@@ -76,9 +75,23 @@ When you create a pixel in Facebook you receive a pixel id.
7675
Now create a new pixel in your Sylius shop by navigating to `/admin/pixels/new`.
7776
Remember to enable the pixel and enable the channels you want to track.
7877

79-
### Step 7: You're ready!
78+
### Step 7. Configure cron
79+
80+
Add `bin/console setono:sylius-facebook:send-pixel-events` command to your crontab.
81+
82+
Schedule must be hourly or more frequently.
83+
See [notes](https://developers.facebook.com/docs/marketing-api/conversions-api/using-the-api#batch-requests).
84+
85+
### Step 8: You're ready!
8086
The events that are tracked are located in the [EventListener folder](src/EventListener).
8187

88+
## Related links
89+
- https://developers.facebook.com/docs/marketing-api/audiences/guides/dynamic-product-audiences/#setuppixel
90+
- https://developers.facebook.com/docs/marketing-api/conversions-api
91+
- https://developers.facebook.com/docs/marketing-api/conversions-api/using-the-api
92+
- https://developers.facebook.com/docs/marketing-api/conversions-api/guides/business-sdk-features
93+
- https://github.com/facebook/facebook-php-business-sdk
94+
8295
## Contribute
8396
Ways you can contribute:
8497
* Translate [messages](src/Resources/translations/messages.en.yaml) and [validators](src/Resources/translations/validators.en.yaml) to your mother tongue

UPGRADE.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# UPGRADE FROM `1.0.x` to `2.0.x`
2+
3+
1. As we're moving to server side tracking - we no longer need `SetonoTagBagBundle`
4+
and `SetonoSyliusTagBagPlugin`.
5+
6+
- Remove them from `config/bundles.php`:
7+
8+
```diff
9+
$bundles = [
10+
- Setono\TagBagBundle\SetonoTagBagBundle::class => ['all' => true],
11+
- Setono\SyliusTagBagPlugin\SetonoSyliusTagBagPlugin::class => ['all' => true],
12+
+ Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
13+
+ Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
14+
15+
Setono\SyliusFacebookPlugin\SetonoSyliusFacebookPlugin::class => ['all' => true],
16+
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
17+
];
18+
```
19+
20+
- Remove `setono/sylius-tag-bag-plugin` if it used
21+
22+
```bash
23+
composer remove setono/sylius-tag-bag-plugin
24+
```
25+
26+
1. Remove custom event listeners extended from `Setono\SyliusFacebookPlugin\EventListener\TagSubscriber`
27+
from your application:
28+
29+
```php
30+
- namespace App\EventListener;
31+
32+
- use Setono\SyliusFacebookPlugin\EventListener\AbstractSubscriber;
33+
34+
- final class SomeTagSubscriber extends AbstractSubscriber
35+
- {
36+
- ...
37+
- }
38+
```
39+
1. Configure Access token
40+
41+
```yaml
42+
# config/packages/setono_sylius_facebook.yaml
43+
...
44+
setono_sylius_facebook:
45+
access_token: '%env(FACEBOOK_ACCESS_TOKEN)%'
46+
```
47+
48+
```dotenv
49+
# .env
50+
###> setono/sylius-facebook-plugin ###
51+
FACEBOOK_ACCESS_TOKEN=<YOUR TOKEN>
52+
###< setono/sylius-facebook-plugin ###
53+
```
54+
1. `src/EventListener/TagSubscriber.php -> src/EventListener/AbstractSubscriber.php`
55+
56+
1. Add `bin/console setono:sylius-facebook:send-pixel-events`
57+
command call to your CRON

composer.json

+33-8
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,41 @@
1111
"license": "MIT",
1212
"require": {
1313
"php": ">=7.4",
14+
"ext-json": "*",
15+
"facebook/php-business-sdk": "^12.0",
1416
"psr/event-dispatcher": "^1.0",
15-
"setono/tag-bag-bundle": "^2.0",
16-
"setono/tag-bag-twig": "^1.0",
17+
"psr/log": "^1.1",
18+
"setono/client-id-bundle": "^0.2",
19+
"setono/client-id-contracts": "^0.2",
20+
"setono/consent-bundle": "^0.1",
21+
"setono/consent-contracts": "^0.1",
1722
"sylius/resource-bundle": "^1.6",
1823
"symfony/config": "^4.4 || ^5.0",
19-
"thecodingmachine/safe": "^1.0"
24+
"symfony/console": "^4.4 || ^5.0",
25+
"symfony/dependency-injection": "^4.4 || ^5.0",
26+
"symfony/event-dispatcher": "^4.4 || ^5.0",
27+
"symfony/form": "^4.4 || ^5.0",
28+
"symfony/http-client": "^5.3",
29+
"symfony/http-client-contracts": "^2.4",
30+
"symfony/http-foundation": "^4.4 || ^5.0.7",
31+
"symfony/http-kernel": "^4.4 || ^5.1.5",
32+
"symfony/messenger": "^4.4 || ^5.0",
33+
"symfony/routing": "^4.4 || ^5.0",
34+
"symfony/serializer": "^4.4 || ^5.0",
35+
"symfony/workflow": "^4.4 || ^5.0",
36+
"thecodingmachine/safe": "^1.0",
37+
"webmozart/assert": "^1.10"
2038
},
2139
"require-dev": {
40+
"matthiasnoback/symfony-config-test": "^4.3",
41+
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
2242
"phpspec/phpspec": "^6.3",
2343
"phpunit/phpunit": "^9.5",
44+
"psalm/plugin-phpunit": "^0.16.0",
45+
"psalm/plugin-symfony": "^2.4",
2446
"roave/security-advisories": "dev-latest",
25-
"setono/code-quality-pack": "^1.5.1",
47+
"setono/code-quality-pack": "^2.1.2",
2648
"setono/sylius-behat-pack": "^0.1",
27-
"setono/sylius-tag-bag-plugin": "^1.1",
2849
"sylius/sylius": "~1.7.0",
2950
"symfony/debug-bundle": "^5.1",
3051
"symfony/dotenv": "^5.2",
@@ -54,9 +75,13 @@
5475
},
5576
"prefer-stable": true,
5677
"scripts": {
57-
"analyse": "phpstan analyse -c phpstan.neon -l max src",
58-
"check-style": "ecs check --ansi spec src",
59-
"fix-style": "ecs check --ansi spec src --fix",
78+
"analyse": [
79+
"@ensure-test-container-exists",
80+
"psalm"
81+
],
82+
"check-style": "ecs check --ansi",
83+
"ensure-test-container-exists": "[[ -f tests/Application/var/cache/test/ApplicationTests_Setono_SyliusFacebookPlugin_Application_KernelTestDebugContainer.xml ]] || tests/Application/bin/console cache:warmup --env=test",
84+
"fix-style": "ecs check --ansi --fix",
6085
"phpspec": "phpspec run --ansi",
6186
"phpunit": "phpunit"
6287
}

easy-coding-standard.yml

-2
This file was deleted.

ecs.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
6+
use Symplify\EasyCodingStandard\ValueObject\Option;
7+
8+
return static function (ContainerConfigurator $containerConfigurator): void {
9+
$containerConfigurator->import('vendor/sylius-labs/coding-standard/ecs.php');
10+
$containerConfigurator->parameters()->set(Option::PATHS, [
11+
'src',
12+
'tests',
13+
]);
14+
$containerConfigurator->parameters()->set(Option::SKIP, [
15+
'tests/Application/**',
16+
]);
17+
};

psalm.xml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
totallyTyped="true"
5+
xmlns="https://getpsalm.org/schema/config"
6+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
7+
>
8+
<projectFiles>
9+
<directory name="spec"/>
10+
<directory name="src"/>
11+
<directory name="tests"/>
12+
<ignoreFiles>
13+
<directory name="tests/Application"/>
14+
<directory name="vendor"/>
15+
</ignoreFiles>
16+
</projectFiles>
17+
<plugins>
18+
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin">
19+
<containerXml>tests/Application/var/cache/test/ApplicationTests_Setono_SyliusFacebookPlugin_Application_KernelTestDebugContainer.xml</containerXml>
20+
</pluginClass>
21+
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
22+
</plugins>
23+
<issueHandlers>
24+
<UnnecessaryVarAnnotation errorLevel="suppress"/> <!-- We only use 'unnecessary' var annotations when we want to help PhpStorm :) -->
25+
<DeprecatedMethod>
26+
<errorLevel type="suppress">
27+
<referencedMethod name="Symfony\Component\HttpFoundation\RequestStack::getMasterRequest"/>
28+
</errorLevel>
29+
</DeprecatedMethod>
30+
</issueHandlers>
31+
</psalm>

spec/Event/BuilderEventSpec.php

-28
This file was deleted.

src/Builder/AddToCartBuilder.php

-14
This file was deleted.

src/Builder/Builder.php

-36
This file was deleted.

src/Builder/BuilderInterface.php

-20
This file was deleted.

0 commit comments

Comments
 (0)