I’m new to Mautic and have a rather basic question regarding the campaigns. Is it somehow possible to redirect a customer inside a running campaign? I know that it is possible right after submitting a form, but I would need it a step further after checking a contact field.
The workflow would be something like this:
Submit form → Campaign starts → Check if a certain field is set “TRUE” → Redirect to a specific URL
I hope I could clearify my issue here. Would be thankful for every new idea
perhaps people have a easier solution than I, but I see 2 ways to do what you want both relies on javascript to redirect the user to a specific url, the basic code is:
option 1 , is to setup a page to be redirected after the form is submitted, lets say a thank you page. this page has a dynamic web content (Dynamic Web Content (DWC) | Mautic), which can be defined by a campaign or just a regular dwc based on the contact’s field. the redirect code to be used will be included in that dynamic web content
option 2 can be used when the data used to decide the redirected was collected in the form, so after submitting the form you can intercept the response from mautic and in case of successfully submit, redirect the user to another page. I use this option in scenarios that the response of the form will lead the user to additional questions (another form). for this scenario the script is a little more complex:
<script>
if (typeof MauticFormCallback == 'undefined') var MauticFormCallback = {};
var vFormName = 'FormName' //the name of the mautic form here
MauticFormCallback[vFormName] = {
onResponse: function (response) {
//handle the response from mautic
if( response.success == 1 ) {
if( response.results.formField1 == "option1" )
{
location.href="https://mautic-server.com/option1-page";
} else if(response.results.formField1 == "option2" ) {
location.href="https://mautic-server.com/option2-page";
}else {
location.href="https://mautic-server.com/option3-page";
}
}
}
};
yesss, that’s exactly what I had in mind. Thank you a lot
But unfortunatly the first option is not quite working for me. I successfully included the DWC into my web page. Using the classic examples I can see the content of each dynamic page. However, the moment I include the redirect script my web page loads the thank you page, shows for a second the content inside the div-tags (“Dynamic web content for myslot”) and disappears and nothing happens afterwards.
Any idea what I’m doing wrong? I’m using WordPress for displaying the content and I integrated the script like this into the DWC:
is there a page i can visit to test it? the fact that the default value disappears is an indication that the content is being loaded, perhaps there is something else preventing the content to be loaded…
you can try to include something outside the script tag to help with the debug like <p>I am a dwc</p>
Unfortunately, everything is on a local setup, so testing is not possible right now. And I have to confess that I’m still using version 3.3.3 because of some personal modifications on Mautic. However, I couldn’t find any community issues in the past with JS inside DWC. That seems like the problem here because everything is running apart from the script-tag.
I will run some tests tomorrow and try to identify the exact problem, hopefully Appreciate your help so far @leoschuler
I was able to test in my environment (also 3.3.3), I found some issues but fortunately I was able to workaround it, here is my findings:
if you include just the redirect script you will have trouble saving and editing the DWC because the script will execute and redirect while editing it, so I include an extra if to avoid redirect while in the edit page:
The second issue is related to the dwc Text editor, even when working with pure html, after saving the content will be auto formatting , and then, when loading to a page, extra space and html code might interfere with the javascript code, in the image below you can see how the code was loaded into the browser and add “ ” text where it should not, breaking the code:
I had to remove indentation and curly brackets, which means a complex javascript code will never work that way, for those case another workaround would be to create a .js file and just link it instead of typing the javascript inline like I did.
you can see it working in here: form-page - is a page containing the form, so mautic can recognize you, once submitted the contact will be redirected to: Redirect Test - is the " thank you " page, it will only redirect the user if the user is recognized (as an email), if not it will stay in the page.