Tracking domains and redirection

Jerry

New Member
Hello,

There's a tracking domain that is connected to delivery server. Customers receive proper email with links that point to that domain, however after clicking on that link MailWizz redirects them to the DEFAULT domain instead of tracking one.

After digging a bit into MailWizz code I've ended with next conclusions:

CampaignsController::actionTrack_url($campaign_uid, $subscriber_uid, $hash) calls
CampaignHelper::parseContent($destination, $campaign, $subscriber, false) to retrieve URL to redirect to. In turn, it calls self::getCommonTagsSearchReplace($content, $campaign, $subscriber) to replace [XYZ] template fields with correct ones. If we open that function we will see that it uses system absolute URLs to build the link:
$unsubscribeUrl = $options->get('system.urls.frontend_absolute_url') . 'lists/' . $list->list_uid . '/unsubscribe';

And this is the reason why it redirect to DEFAULT domain instead of a tracking one.

Question is how can I fix it in a proper way as I don't have much experience with Yii and don't want to break anything ESPECIALLY ability to upgrade without pain.

Thanks,
Jerry.
 
If the links properly point to your tracking domain, then everything is fine mailwizz wise, but the problem is that the domain where mailwizz is installed is not the default domain on your server, therefore, when a cname to this domain is accessed, it returns the default domain on the server, which is not the one where mailwizz is installed and you get the error you get.
 
If the links properly point to your tracking domain, then everything is fine mailwizz wise, but the problem is that the domain where mailwizz is installed is not the default domain on your server, therefore, when a cname to this domain is accessed, it returns the default domain on the server, which is not the one where mailwizz is installed and you get the error you get.

Uh, it's not an error. Let me explain it again. There's a server with default domain a.com. On that server MailWizz is installed at mailwizz.a.com. There's tracking domain track.b.com which is configured in DNS as CNAME to mailwizz.a.com and is attached to delivery server.

So, when subscriber receives an email he see unsubscribe link starting with tracking.b.com which is perfect. However when he clicks on that link he gets redirected to a.com instead of landing on tracking.b.com.

I've found out that this is because of $unsubscribeUrl = $options->get('system.urls.frontend_absolute_url') . 'lists/' . $list->list_uid . '/unsubscribe'; within CampaignHelper.php

Can you please suggest how do I properly handle this situation from within a php code to replace $options->get('system.urls.frontend_absolute_url') with actual tracking domain from the database? I thought somethging about this:

PHP:
if (!empty($campaign->deliveryServers)) {
     $deliveryServer = $campaign->deliveryServers[0];
     if (!empty($deliveryServer->trackingDomains)) {
          $deliveryServer = $deliveryServer->trackingDomains[0];
          // replace string...
     }
}
But what to do if there are many delivery server each one with separate tracking domain etc.

Thank you.
 
O.K. if someone needs this functionality you can use next piece of code:

PHP:
<?php defined('MW_PATH') || exit('No direct script access allowed');

class RewriteTrackingDomainExt extends ExtensionInit
{
    // name of the extension as shown in the backend panel
    public $name = 'Rewrite tracking domain';

    // description of the extension as shown in backend panel
    public $description = 'Rewrite tracking domain';

    // current version of this extension
    public $version = '1.0';

    // the author name
    public $author = 'Jerry';

    // author website
    public $website = 'http://www.google.com';

    // contact email address
    public $email = 'nobody@nowhere.com';

    // in which apps this extension is allowed to run
    public $allowedApps = array('*');

    // can this extension be deleted? this only applies to core extensions.
    protected $_canBeDeleted = true;

    // can this extension be disabled? this only applies to core extensions.
    protected $_canBeDisabled = true;

    // run the extension, ths is mandatory
    public function run()
    {
        Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_rewriteTrackingDomain'));
    }
   
    public function _rewriteTrackingDomain($campaignsController, $campaign, $subscriber, $url, $destination) {
       
        if (!empty($campaign->deliveryServers)) {   
       
            foreach($campaign->deliveryServers as $deliveryServer) {
               
                if (!empty($deliveryServer->trackingDomain)) {
                   
                    // check if destination has default domain name
                    $defaultDomainHost = parse_url(Yii::app()->options->get('system.urls.frontend_absolute_url'), PHP_URL_HOST);
                   
                    $destinationHost = parse_url($destination, PHP_URL_HOST);
                   
                    if ($destinationHost === $defaultDomainHost) {
                       
                        $destination = str_replace($defaultDomainHost, $deliveryServer->trackingDomain->name, $destination);

                        $campaignsController->redirect($destination, true, 301);
                    }
                }
            }
        }
    }
}

Save the file as RewriteTrackingDomainExt.php in folder rewrite-tracking-domain and archive folder as .zip. Then upload extension and enable it. I know it's an ugly hack but it works for me since I use only one delivery server / tracking domain per campaign.

Cheers,
Jerry
 
So, when subscriber receives an email he see unsubscribe link starting with tracking.b.com which is perfect. However when he clicks on that link he gets redirected to a.com instead of landing on tracking.b.com.
This really sounds like a server issue to me since mailwizz does not do such redirect.
Are you sure you have no .htaccess with some fancy rules?
If you access http://tracking.b.com/customer what do you get?
Last thing, using mailwizz 1.3.5.7?
 
This really sounds like a server issue to me since mailwizz does not do such redirect.
Are you sure you have no .htaccess with some fancy rules?
If you access http://tracking.b.com/customer what do you get?
Last thing, using mailwizz 1.3.5.7?

Yes, I am using latest 1.3.5.7.
No, I don't have .htaccess for MailWizz at all.
When I open http://tracking.b.com/customer I see Customer log in screen as it should be.
And yes, MailWizz performs such a redirect by itself. When subscriber clicks on a link with tracking.b.com he arrives to CampaignsController::actionTrack_url(...) where
Code:
CampaignHelper::parseContent($destination, $campaign, $subscriber, false)
is called which calls self::getCommonTagsSearchReplace(...) that forms final link via $unsubscribeUrl = $options->get('system.urls.frontend_absolute_url') . 'lists/' . $list->list_uid . '/unsubscribe'; As you can see $options->get('system.urls.frontend_absolute_url') will ALWAYS return system absolute url (which is http://a.com/index.php/) and NEVER tracking domain URL.

Please, fix me if I am wrong, but the only solutions that worked for me I've posted previously in this thread.
 
Hello.
Sorry for my English:(
Please tell me what could be the problem?
Established mailwizz 1.3.5.8
if you do not include tracking domains the script is working properly
If you turn on tracking domains that letters come with the wrong link of this kind http://tracking.site.ru/lists/vx962q228m8bd/confirm-subscribe/sj042wgyjy9ec
tracking.site.ru and should be mail.site.ru
Record tracking CNAME mail.site.ru. created
Mailwizz 1.3.5.8 The script is located in the subdomain mail.site.ru
.htaccess is created without errors.
Please tell me what should I do?
Thank you.
 
Hey,

That's the purpose of the tracking domains, to change the original domain name with another one.
This works as expected, not sure what the issue is...

Thanks.
 
I'm using 1.3.5.8 and having the same issue. The tracking domain redirection doesn't work properly and will show the original domain when viewing "Web Version" of template. Using 2 different installations on two different servers without .htaccess.
 
Back
Top