I think the problem is that your redirect is occuring before the default redirect and hence has no effect.
Here's a module that does the job:
Module directory structure:
| registration.php
|
+---etc
| | di.xml
| | module.xml
| |
| \---frontend
| events.xml
|
+---Observer
| Register.php
|
\---Plugin
Redirect.php
di.xml :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Model\Account\Redirect">
<plugin name="NewAcctRedirectPlug" type="Your\Module\Plugin\Redirect" disabled="false" sortOrder="1"/>
</type>
</config>
events.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="customer_register_success">
<observer name="custom_redirect_register_success" instance="Your\Module\Observer\Register" disabled="false"/>
</event>
</config>
Register.php:
<?php
namespace Your\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Registry;
class Register implements ObserverInterface
{
protected $coreRegistry;
public function __construct(Registry $registry)
{
$this->coreRegistry = $registry;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$this->coreRegistry->register('is_new_account', true);
}
}
Redirect.php:
<?php
namespace Your\Module\Plugin;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
class Redirect
{
protected $coreRegistry;
protected $url;
protected $resultFactory;
public function __construct(Registry $registry, UrlInterface $url, ResultFactory $resultFactory)
{
$this->coreRegistry = $registry;
$this->url = $url;
$this->resultFactory = $resultFactory;
}
public function aroundGetRedirect ($subject, \Closure $proceed)
{
if ($this->coreRegistry->registry('is_new_account')) {
/** @var \Magento\Framework\Controller\Result\Redirect $result */
$result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$result->setUrl($this->url->getUrl('custom/path'));
return $result;
}
return $proceed();
}
}
It works by setting a flag in the core registry when the customer_register_success
event occurs and then checks for that flag and returns an alternate redirect path when the redirect for a successful customer authentication is requested instead of the default 'My Account' page. Hope this helps.