-
Notifications
You must be signed in to change notification settings - Fork 81
Raptor integration - feature branch #3121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 5.0
Are you sure you want to change the base?
Changes from all commits
3583d90
6be8b25
0e888f8
f99ef95
2e6f571
9307035
0930200
5c30896
ae73918
5fab98d
0493195
701594d
6aa1709
3fe76fa
4a4de00
3c252cb
916b1b3
42f564e
9417292
745d3ff
1f7bb23
5d231e3
28025cc
fba3463
1f400e1
3ca94b5
771e1e0
e44ed16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <?php declare(strict_types=1); | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\Event\VisitEventData; | ||
|
|
||
| $eventData = new VisitEventData( | ||
| productCode: $product->getCode(), | ||
|
Check failure on line 5 in code_samples/recommendations/EventData.php
|
||
| productName: $product->getName(), | ||
|
Check failure on line 6 in code_samples/recommendations/EventData.php
|
||
| categoryPath: '25#Electronics;26#Smartphones', // Build manually | ||
| currency: 'USD', | ||
| itemPrice: '999.99' | ||
| ); | ||
|
|
||
| $this->trackingDispatcher->dispatch($eventData); | ||
|
Check failure on line 12 in code_samples/recommendations/EventData.php
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php declare(strict_types=1); | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\EventMapperInterface; | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\EventType; | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\ServerSideTrackingDispatcherInterface; | ||
| use Ibexa\Contracts\ProductCatalog\Values\ProductInterface; | ||
|
|
||
| class EventMapper | ||
| { | ||
| public function __construct( | ||
| private readonly EventMapperInterface $eventMapper, | ||
| private ServerSideTrackingDispatcherInterface $trackingDispatcher, | ||
| ) { | ||
| } | ||
|
|
||
| public function trackProductView(ProductInterface $product, string $url): void | ||
julitafalcondusza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Map product to VisitEventData automatically | ||
| $eventData = $this->eventMapper->map(EventType::VISIT, $product); | ||
|
|
||
| // Send tracking event | ||
| $this->trackingDispatcher->dispatch($eventData); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php declare(strict_types=1); | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\EventMapperInterface; | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\EventType; | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\ServerSideTrackingDispatcherInterface; | ||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
| use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
| use Symfony\Component\HttpKernel\KernelEvents; | ||
|
|
||
| class EventSubscriber implements EventSubscriberInterface | ||
| { | ||
| public function __construct( | ||
| private readonly EventMapperInterface $eventMapper, | ||
| private ServerSideTrackingDispatcherInterface $trackingDispatcher, | ||
| ) { | ||
| } | ||
|
|
||
| public static function getSubscribedEvents(): array | ||
| { | ||
| return [KernelEvents::RESPONSE => ['onResponse', -10]]; | ||
| } | ||
|
|
||
| public function onResponse(ResponseEvent $event): void | ||
| { | ||
| if (!$event->isMainRequest()) { | ||
| return; | ||
| } | ||
|
|
||
| $request = $event->getRequest(); | ||
|
|
||
| // Example: track only if request has specific attribute | ||
| $product = $request->attributes->get('product'); | ||
| if (null === $product) { | ||
| return; | ||
| } | ||
|
|
||
| $eventData = $this->eventMapper->map(EventType::VISIT, $product); | ||
| $this->trackingDispatcher->dispatch($eventData); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ibexa: | ||
| system: | ||
| <scope>: | ||
| connector_raptor: | ||
| enabled: true | ||
| customer_id: ~ # Required | ||
| tracking_type: client # One of: "client" or "server" | ||
|
|
||
| # Raptor Recommendations API key | ||
| recommendations_api_key: ~ # Required | ||
|
|
||
| # Raptor Recommendations API URL, optional, set by default | ||
| recommendations_api_url: '%ibexa.connector.raptor.recommendations.api_url%' | ||
| ibexa_connector_raptor: | ||
| # When enabled, tracking exceptions are thrown instead of being silently handled | ||
| strict_exceptions: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| ``` html | ||
| <!-- Cookie Consent by TermsFeed https://www.TermsFeed.com --> | ||
| <script type="text/javascript" src="https://www.termsfeed.com/public/cookie-consent/4.2.0/cookie-consent.js" charset="UTF-8"></script> | ||
| <script type="text/javascript" charset="UTF-8"> | ||
| document.addEventListener('DOMContentLoaded', function () { | ||
| cookieconsent.run({ | ||
| "notice_banner_type": "simple", | ||
| "consent_type": "implied", | ||
| "palette": "dark", | ||
| "language": "en", | ||
| "page_load_consent_levels": ["strictly-necessary"], | ||
| "notice_banner_reject_button_hide": false, | ||
| "preferences_center_close_button_hide": false, | ||
| "page_refresh_confirmation_buttons": false, | ||
| "website_name": "Ibexa Storefront", | ||
| "callbacks": { | ||
| "scripts_specific_loaded": (level) => { | ||
| switch(level) { | ||
|
Check warning on line 18 in code_samples/recommendations/custom_integration.html
|
||
| case 'tracking': | ||
| document.dispatchEvent(new CustomEvent('enableTracking')); | ||
| break; | ||
| } | ||
| } | ||
| }, | ||
| "callbacks_force": true | ||
| }); | ||
| }); | ||
| </script> | ||
| <noscript>Free cookie consent management tool by <a href="https://www.termsfeed.com/">TermsFeed</a></noscript> | ||
| <!-- End Cookie Consent by TermsFeed https://www.TermsFeed.com --> | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| {# templates/cart/add_confirmation.html.twig #} | ||
| {% extends 'base.html.twig' %} | ||
|
|
||
| {% block content %} | ||
| <div class="cart-notification"> | ||
| <p>Product "{{ product.name }}" has been added to your cart!</p> | ||
| <p>Quantity: {{ addedQuantity }}</p> | ||
| </div> | ||
|
|
||
| {# Build basket content string: "product-code:quantity;product-code:quantity" #} | ||
| {% set basketContent = [] %} | ||
| {% for entry in cart.entries %} | ||
| {% set basketContent = basketContent|merge([entry.product.code ~ ':' ~ entry.quantity]) %} | ||
| {% endfor %} | ||
| {# Track basket addition #} | ||
| {% set basketContext = { | ||
| 'basketContent': basketContent|join(';'), | ||
| 'basketId': cart.id, | ||
| 'quantity': addedQuantity | ||
| } %} | ||
julitafalcondusza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| {{ ibexa_tracking_track_event('basket', product, basketContext) }} | ||
|
|
||
| <a href="{{ path('cart_view') }}">View Cart</a> | ||
| {% endblock %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| {# templates/bundles/IbexaCoreBundle/default/content/full.html.twig #} | ||
| {% extends '@!IbexaCore/default/content/full.html.twig' %} | ||
|
|
||
| {% block content %} | ||
| {{ parent() }} | ||
| {{ ibexa_tracking_track_event('contentvisit', content) }} | ||
| {% endblock %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| {{ ibexa_tracking_track_event('itemclick', product.code, { | ||
| 'moduleName': 'homepage-recommendations', | ||
| 'redirectUrl': path('ibexa.product.view', {'productCode': product.code}) | ||
| }) }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # templates/product/view.html.twig #} | ||
| {% extends 'base.html.twig' %} | ||
|
|
||
| {% block content %} | ||
| <div class="product-details"> | ||
| <h1>{{ product.name }}</h1> | ||
| <p>{{ product.description }}</p> | ||
| <div class="price">{{ product.price }}</div> | ||
julitafalcondusza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
|
|
||
| {# Track product visit #} | ||
| {{ ibexa_tracking_track_event('visit', product) }} | ||
| {% endblock %} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| {% extends '@IbexaConnectorRaptor/themes/standard/ibexa/tracking/script.html.twig' %} | ||
| {% block ibexa_tracking_script %} | ||
| console.log('My custom tracking script, but relying on loadTracking function.'); | ||
| {% endblock %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| <script type="text/javascript"> | ||
| if (myCustomConsentIsGiven) { | ||
| {{ include('@ibexadesign/ibexa/tracking/script.js.twig', {'customer_id': customer_id}) }} | ||
| } | ||
| </script> | ||
julitafalcondusza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {# templates/pagelayout.html.twig #} | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| {# ... other head content ... #} | ||
|
|
||
| {# Initialize Raptor tracking - must be called before any tracking events #} | ||
| {{ ibexa_tracking_script() }} | ||
| </head> | ||
| <body> | ||
| {# ... page content ... #} | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| {{ ibexa_tracking_track_event( | ||
| 'visit', | ||
| product, | ||
| {}, | ||
| '@App/tracking/custom_visit.html.twig' | ||
| ) }} | ||
| ``` | ||
|
|
||
| {# templates/tracking/custom_visit.html.twig #} | ||
|
|
||
| {# | ||
| # Custom visit tracking template | ||
| # | ||
| # Available variables: | ||
| # - parameters: array of Raptor tracking parameters (p1, p2, p3, etc.) | ||
| # - debug: boolean flag to enable debug console messages | ||
| #} | ||
|
|
||
| <script type="text/javascript"> | ||
| {% autoescape 'js' %} | ||
| (function () { | ||
| // Custom logic before tracking | ||
| console.log('Custom visit tracking template'); | ||
| console.log('Tracking parameters:', {{ parameters|json_encode|raw }}); | ||
|
|
||
| // Send the tracking event (REQUIRED for tracking to work) | ||
| const event = 'trackEvent'; | ||
| const params = {{ parameters|json_encode|raw }}; | ||
| window.raptor.push(event, params); | ||
|
|
||
| // Custom logic after tracking | ||
| {% if debug %} | ||
| console.log('Visit event tracked successfully'); | ||
| {% endif %} | ||
| })(); | ||
| {% endautoescape %} | ||
| </script> |
Uh oh!
There was an error while loading. Please reload this page.