combindma / laravel-facebook-pixel

Meta Pixel integration for Laravel
MIT License
33 stars 9 forks source link

Request feature for dynamic setting Pixel #1

Closed SanjayaDev closed 2 years ago

SanjayaDev commented 2 years ago

I have a project and inside the project have menu for setting Pixel ID. How to setting Dynamic Pixel ID? Or if feature haven't, can i request feature it?

omarherri commented 2 years ago

At the moment the Pixel ID is specified in the config file. But you can publish the config file php artisan vendor:publish --tag="facebook-pixel-config" and in your controller when the user change the pixel Id you can edit the config file in the fly with this code:

$newPixelId = $request->pixelId;
$facebookConfig = file_get_contents(config_path('facebook-pixel.php'));
file_put_contents(config_path('facebook-pixel.php'), str_replace(
            "'facebook_pixel_id' => env('FACEBOOK_PIXEL_ID', '')",
            "'facebook_pixel_id' => env('FACEBOOK_PIXEL_ID', '".$newPixelId."')",
            $facebookConfig
));

Another option is to set the Pixel Id for every request you use this package. For that you can see the section Macrobale in the documentation where you can create your own Macro and add your code.