Skip to content

Conversation

Syrgak-Alan
Copy link
Contributor

@Syrgak-Alan Syrgak-Alan commented Jan 15, 2024

Q A
Bug fix? (use the a.b branch) [✖️]
New feature/enhancement? (use the a.x branch) [✔️ ]
Deprecations? [✖️ ]
BC breaks? (use the c.x branch) [✖️ ]
Automated tests included? [✖️ ]
Related user documentation PR URL mautic/mautic-documentation#...
Related developer documentation PR URL mautic/developer-documentation#...
Issue(s) addressed Fixes #...

Description:

Leuchtfeuer.com

This enhancement will allow to add another filters for your dynamic web content by listening to DynamicContentEvents::ON_CONTACTS_FILTER_EVALUATE event. To add new filter, subscriber of wished filter has to listen to Mautic\LeadBundle\LeadEvents::LIST_FILTERS_CHOICES_ON_GENERATE event and store a choice in LeadListFiltersChoicesEvent, in LeadBundle\EventListener\FilterOperatorSubscriber is an example how could it be implemented.

(this enhancement works for this moment only for landing pages. I want firstly get some feedback, if PR is good I will commit changes for email bundle too)

As requested, here is an example how could be used such enhancement:

In this plugin is possible to filter DWC by device type of page's visitor:
https://github.com/Leuchtfeuer/mautic-DwcDeviceType-bundle
Steps to test this:

  1. In /plugins/ directory clone this plugin
  2. Rename plugin name from mautic-DwcDeviceType-bundle to LeuchtfeuerDwcDeviceTypeBundle(otherwise it's not going to work)
  3. Clear the cache
  4. Enble plugin if it's not
  5. Create new DWC which one is not campaign based and choose as filter - device type
  6. Set this DWC in landing page by slot name

Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Add some plugin which listens to ON_CONTACTS_FILTER_EVALUATE event and enable this
  3. Create DWC which is NOT campaign based(set a slot name) and add filters that you need
  4. Place DWC into your landing page by setting in your page builder {dwc=<slot_name>}

@Syrgak-Alan Syrgak-Alan changed the title Enhances filters evaluation by allowing to extend core filters by another filters for pages Enhances filters evaluation for DWCs Jan 17, 2024
@kuzmany
Copy link
Member

kuzmany commented Jan 17, 2024

@Syrgak-Alan Can you please add an example to the description of how the new filter could look in the subscriber? It would help test this pull request.

@Syrgak-Alan
Copy link
Contributor Author

Syrgak-Alan commented Jan 17, 2024

@kuzmany if I understood you correctly, how namely I wrote evaluation for extended filter which subscribes the event? Or how I added this filter to the list of options

@kuzmany
Copy link
Member

kuzmany commented Jan 19, 2024

@Syrgak-Alan we need part of the code that will test it. Simple subscriber what add new filter and provide it in result. It can be whatever, you can create just another contact email filter.

@Syrgak-Alan
Copy link
Contributor Author

@kuzmany I provided a snippet of code, which evaluates extended filter

@ekkeguembel
Copy link

@kuzmany I provided a snippet of code, which evaluates extended filter

@Syrgak-Alan where can I find that?

Copy link

@MadlenF MadlenF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this PR as requirement for https://github.com/Leuchtfeuer/mautic-DwcDeviceType-bundle - looks good from user-perpective! 👍

Copy link
Member

@kuzmany kuzmany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my side it does not need these kind of changes.
You can use your own filters validation on your https://github.com/Leuchtfeuer/mautic-DwcDeviceType-bundle/blob/main/EventListener/DynamicContentSubscriber.php

And other filters (not related to your added filters) you can use validation from trait app/bundles/EmailBundle/EventListener/MatchFilterForLeadTrait.php

Something like

     foreach ($filters as $key=>$filter) {
            if ('device_type' === $filter['type']) {
            
            // your logic determine results, not passed return false
            //     $event->setIsEvaluated(true);
            //            $event->setIsMatched(false);
            // return;
            
            // unset custom filters
            unset(filters[$key])
            }
}
// if your custom filters validation passed, then continue rest of filters validate with regular expressions
               $event->setIsEvaluated(true);
                $event->setIsMatched($this->matchFilterForLead($filters, $leadArray));

@Syrgak-Alan
Copy link
Contributor Author

Syrgak-Alan commented Feb 19, 2024

@kuzmany

From my side it does not need these kind of changes. You can use your own filters validation on your

https://github.com/Leuchtfeuer/mautic-DwcDeviceType-bundle/blob/main/EventListener/DynamicContentSubscriber.php

What do you mean by From my side it does not need these kind of changes?
Honestly I didn't quite understand your suggestion in trait and filter validation

@biozshock
Copy link
Contributor

@kuzmany I've took over this task.

The PR actually solves the problem: in the method \Mautic\DynamicContentBundle\EventListener\DynamicContentSubscriber::decodeTokens any inclusion of {dwc=slot_name}Slot content, that is found by the \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::findDwcTokens in the said content, the token will not be replaced, because the event ContactFiltersEvaluateEvent is not called for the "content-included DWC", because the the event is called only after the $xpath->query('//*[@data-slot="dwc"]'); in the \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::getDynamicContentForLead and then in the \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::getDynamicContentSlotForLead and then in the \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::filtersMatchContact.
Your proposed solution works only for the DWC tokens presented in the HTML with the data-slot="dwc", not for the {dwc content token.

In addition i found that the DWC stats are not properly creating stats entry:
The method \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::findDwcTokens call the \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::getRealDynamicContent, which in turn calls the \Mautic\DynamicContentBundle\Model\DynamicContentModel::createStatEntry, which populate the dynamic_content_stats with DWC token stats that are only matched in the content, but are not displayed to the Lead, if they are not matched later.

I would propose two different solutions:

  1. Extend the PR to remove the unnecessary pass of $extendedFiltersPassed
  2. Change the PR to use \Mautic\DynamicContentBundle\Helper\DynamicContentHelper::getDynamicContentSlotForLead instead of \Mautic\EmailBundle\EventListener\MatchFilterForLeadTrait::matchFilterForLead in the \Mautic\DynamicContentBundle\EventListener\DynamicContentSubscriber::decodeTokens

@escopecz
Copy link
Member

Closing in favore of #14599. Please test that one as it has tests and passing CI.

@escopecz escopecz closed this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants