Skip to content

Commit

Permalink
Fixed tracking code inclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Nov 16, 2023
1 parent aedf6d9 commit a2d13ab
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions Config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<hooks>
<hook id="brevo.configuration.hook" class="Brevo\Hook\HookManager" scope="request">
<tag name="hook.event_listener" event="module.configuration" type="back" method="onModuleConfiguration" />
<tag name="hook.event_listener" event="main.head-bottom" type="front" method="onMainHeadTop" />
<argument type="service" id="request_stack"/>
<argument type="service" id="event_dispatcher"/>
</hook>
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.7</version>
<version>1.1.8</version>
<authors>
<author>
<name>Chabreuil Antoine</name>
Expand Down
53 changes: 25 additions & 28 deletions Hook/HookManager.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/

/*
* This file is part of the Thelia package.
* http://www.thelia.net
*
* (c) OpenStudio <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/* Copyright (c) OpenStudio */
/* email : [email protected] */
/* web : http://www.thelia.net */

/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */

namespace Brevo\Hook;

Expand All @@ -18,14 +25,12 @@
use Thelia\Core\Event\Hook\HookRenderEvent;
use Thelia\Core\Hook\BaseHook;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Assets\AssetResolverInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\Customer;
use TheliaSmarty\Template\SmartyParser;

class HookManager extends BaseHook
{
/** @var Request */
/** @var Request */
protected $request;

public function __construct(RequestStack $requestStack, EventDispatcherInterface $eventDispatcher)
Expand All @@ -35,30 +40,22 @@ public function __construct(RequestStack $requestStack, EventDispatcherInterface
$this->request = $requestStack->getCurrentRequest();
}

public function onModuleConfiguration(HookRenderEvent $event)
public function onModuleConfiguration(HookRenderEvent $event): void
{
$event->add(
$this->render("brevo-configuration.html")
$this->render('brevo-configuration.html')
);
}

public function onMainHeadTop(HookRenderEvent $event)
public function onMainHeadTop(HookRenderEvent $event): void
{
$apiKey = ConfigQuery::read(Brevo::CONFIG_API_SECRET);

//$this->get('thelia.customer_user');
/** @var Customer $customer */
$customer = $this->request->getSession()->getCustomerUser();

$email = null;
if ($customer !== null) {
$email = $customer->getEmail();
}
$customer = $this->request->getSession()?->getCustomerUser();

$event->add(
$this->render("tracking_script.html",[
'apiKey' => $apiKey,
'email' => $email
$this->render('tracking_script.html', [
'marketingAutomationKey' => ConfigQuery::read(Brevo::CONFIG_AUTOMATION_KEY),
'email' => $customer?->getEmail(),
])
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
var n = document.createElement("script"),
i = document.getElementsByTagName("script")[0];
n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?plugin=prestashop&key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();
n.type = "text/javascript", n.id = "sendinblue-js", n.async = !0, n.src = "https://sibautomation.com/sa.js?plugin=thelia&key=" + window.sib.client_key, i.parentNode.insertBefore(n, i), window.sendinblue.page();
console.log('doner');
})();
</script>

0 comments on commit a2d13ab

Please sign in to comment.