-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3583d90
first batch added
julitafalcondusza 6be8b25
content added
julitafalcondusza 0e888f8
recommendations twig page added
julitafalcondusza f99ef95
updates
julitafalcondusza 2e6f571
content moved, structure updated
julitafalcondusza 9307035
guide added
julitafalcondusza 0930200
guide content
julitafalcondusza 5c30896
fixes, content moved
julitafalcondusza ae73918
fixes after review
julitafalcondusza 5fab98d
Raptor integration - feature branch: fix links (#3123)
adriendupuis 0493195
new batch of fixes
julitafalcondusza 701594d
updates
julitafalcondusza 6aa1709
new blocks added
julitafalcondusza 3fe76fa
name fix
julitafalcondusza 4a4de00
fix
julitafalcondusza 3c252cb
new page added to cards on raptor_connector landing page
julitafalcondusza 916b1b3
fixes - first batch
julitafalcondusza 42f564e
new fixes
julitafalcondusza 9417292
PHP & JS CS Fixes
julitafalcondusza 745d3ff
new fixes
julitafalcondusza 1f7bb23
block names fixed
julitafalcondusza 5d231e3
code fixed
julitafalcondusza 28025cc
code fixed
julitafalcondusza fba3463
links fixed
julitafalcondusza 1f400e1
card fixed
julitafalcondusza 3ca94b5
IBX-11571: Rendering recommendations outside of Page Builder document…
julitafalcondusza 771e1e0
php fix
julitafalcondusza e44ed16
composer.json fix - connector-raptor added
julitafalcondusza e4450f2
Raptor integration - feature branch: Fix PHP (#3130)
adriendupuis 9fb1061
language fixes
julitafalcondusza ce553c5
Raptor integration: Rework PHP (#3131)
adriendupuis b0b4c9b
server description updated
julitafalcondusza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Tracking; | ||
|
|
||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\Event\VisitEventData; | ||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\ServerSideTrackingDispatcherInterface; | ||
| use Ibexa\Contracts\ProductCatalog\Values\ProductInterface; | ||
|
|
||
| class EventData | ||
| { | ||
| public function __construct( | ||
| private readonly ServerSideTrackingDispatcherInterface $trackingDispatcher, | ||
| ) { | ||
| } | ||
|
|
||
| public function dispatchVisitEvent(ProductInterface $product): void | ||
| { | ||
| $eventData = new VisitEventData( | ||
| productCode: $product->getCode(), | ||
| productName: $product->getName(), | ||
| categoryPath: '25#Electronics;26#Smartphones', // Build manually | ||
| currency: 'USD', | ||
| itemPrice: '999.99' | ||
| ); | ||
|
|
||
| $this->trackingDispatcher->dispatch($eventData); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Tracking; | ||
|
|
||
| use Ibexa\Contracts\ConnectorRaptor\Tracking\EventContext; | ||
| 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 readonly ServerSideTrackingDispatcherInterface $trackingDispatcher, | ||
| ) { | ||
| } | ||
|
|
||
| public function trackProductView(ProductInterface $product): void | ||
| { | ||
| // Map product to VisitEventData automatically, override its category | ||
| $eventData = $this->eventMapper->map(EventType::VISIT, $product, [ | ||
| EventContext::CATEGORY_IDENTIFIER => 'electronics', | ||
| ]); | ||
|
|
||
| // Send tracking event | ||
| $this->trackingDispatcher->dispatch($eventData); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace App\Tracking; | ||
|
|
||
| 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 readonly 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); | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
code_samples/recommendations/config/packages/ibexa_connector_raptor.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
| 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 --> | ||
| ``` |
25 changes: 25 additions & 0 deletions
25
code_samples/recommendations/events/basket_event.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} | ||
7 changes: 7 additions & 0 deletions
7
code_samples/recommendations/events/content_visit_event.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
4 changes: 4 additions & 0 deletions
4
code_samples/recommendations/events/itemclicked_event.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}) | ||
| }) }} |
13 changes: 13 additions & 0 deletions
13
code_samples/recommendations/events/product_visit_event.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} | ||
4 changes: 4 additions & 0 deletions
4
code_samples/recommendations/templates/themes/standard/ibexa/tracking/script.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} |
5 changes: 5 additions & 0 deletions
5
code_samples/recommendations/templates/themes/standard/ibexa/tracking/script.js.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
|
||
13 changes: 13 additions & 0 deletions
13
code_samples/recommendations/templates/themes/standard/pagelayout.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
37 changes: 37 additions & 0 deletions
37
code_samples/recommendations/templates/tracking/custom_visit.html.twig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.