davidrobert/setono-sylius-facebook-plugin-fork

Sylius plugin that tracks visitors and sends the data to Facebook

v1.0.0 2022-11-18 10:56 UTC

README

Latest Version Software License Build Status

Track user behavior in Facebook.

Installation

Step 1: Download the plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

$ composer require setono/sylius-facebook-plugin

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the plugin

Then, enable the plugin by adding it to the list of registered plugins/bundles in config/bundles.php file of your project before (!) SyliusGridBundle:

<?php
$bundles = [
    Setono\ClientIdBundle\SetonoClientIdBundle::class => ['all' => true],
    Setono\ConsentBundle\SetonoConsentBundle::class => ['all' => true],
    Setono\BotDetectionBundle\SetonoBotDetectionBundle::class => ['all' => true],
    Setono\SyliusFacebookPlugin\SetonoSyliusFacebookPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];

Step 3: Configure plugin

# config/packages/setono_sylius_facebook.yaml
imports:
    - { resource: "@SetonoSyliusFacebookPlugin/Resources/config/app/config.yaml" }
    
    # Uncomment next line if you want to load some example pixels via fixtures
    # - { resource: "@SetonoSyliusFacebookPlugin/Resources/config/app/fixtures.yaml" }

setono_sylius_facebook:
    access_token: '%env(FACEBOOK_ACCESS_TOKEN)%'
# .env
###> setono/sylius-facebook-plugin ###
FACEBOOK_ACCESS_TOKEN=<YOUR TOKEN>
###< setono/sylius-facebook-plugin ###

Warning! This plugin uses https://github.com/Setono/ConsentBundle and data will not be sent to Facebook by default.

To workaround that on dev environment - you have to configure ConsentBundle like this:

# config/packages/dev/setono_consent.yaml
setono_consent:
    marketing_granted: true

This configuration will make the marketing consent true by default, which means that if you don’t handle consents you will send all events to Facebook by default (which could be against GDPR or other laws related to marketing)

Step 4: Import routing

# config/routes/setono_sylius_facebook.yaml
setono_sylius_facebook:
    resource: "@SetonoSyliusFacebookPlugin/Resources/config/routes.yaml"

Step 5: Update your database schema

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

Step 6: Create a pixel

When you create a pixel in Facebook you receive a pixel id.

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

Step 7. Configure cron

  • Add bin/console setono:sylius-facebook:send-pixel-events command to your crontab.

    Schedule must be hourly or more frequently. See notes.

  • Add bin/console setono:sylius-facebook:cleanup command to your crontab.

    Schedule must be daily or less frequently.

Step 8: You're ready!

The events that are tracked are located in the EventListener folder.

Related links

Contribute

Ways you can contribute:

  • Translate messages and validators to your mother tongue
  • Create Behat tests that verifies the scripts are outputted on the respective pages
  • Create new event subscribers that handle Facebook events which are not implemented

Thank you!