Mautic Community Forums

Show focus item - conditions?

Hi,



any idea on how could I show a focus item to e.g. visitors from a certain country or e.g. contacts that are not already in a segment?



Thanks,

D.


Hi,

any idea on how could I show a focus item to e.g. visitors from a certain country or e.g. contacts that are not already in a segment?

Thanks,
D.

Yes, I can make a workaround for the country on the server (using PHP, I can decide to include the focus JS or not).

Regarding showing a focus only to contacts that are not in a segment yet, could possibly Dynamic Web Content do the trick? I confess I haven’t studied DWS yet, I only read here on the forums that it might help. Am I on the right track at least?

Thank you
D.

I’ll try it later. I’ll post here what I manage to do.

D.

This concept actually works - How to show focus items to visitors that are not part of a segment:

  • add DWC to the webpage like this <div id="focus-dwc" class="mautic-slot" data-slot-name="mautic-dynamic-focus"></div>

  • make the DWC spit out “dont_show_focus” or something similar (i.e. write this string into the dynamic content item in Mautic)

  • create a segment-driven campaign (since we’d like to check if the webpage visitor is part of segment or not) where you just create a request-push DWC pair … this practically means that if the visitor is part of this campaign’s segment, we’ll write the “dont_show_focus” in div#focus-dwc

  • therefore, if after DOM is loaded and all ajax requests are processed, div#focus-dwc contains dont_show_focus, we know that the visitor is part of segment and we don’t want to show him/her the focus item. We can detect this using jQuery and evaluate #focus-dws’s inner html content … yeah, there is some delay and possibly we have a hazard here due to async checking, but normally this works. Also, we can hide the div so that “dont_show_focus” isn’t actually shown on the page using CSS (div#focus-dwc{visibility:hidden;}).

  • on the contrary, if there is not dont_show_focus string in the div, we can use jQuery to load the focus item’s JS code with a simple $.loadScript() call, since we know this visitor is not part of the segment.

It’s hacky as hell, but it works.

Furthermore, if we want to decide to show the focus based on the visitor’s country, we can additionally use server-side (PHP of the webpage) in order to not actually even show div#focus-dwc (so basically, we use PHP to echo out this element (or not) based on the REMOTE_ADDR lookup.

I hope I helped someone using this practice. It may not be the best (yeah, that async checking bothers me) but it works.

Best,
D.