Conditional Common campaign template tags

Yomiit

New Member
Greetings Everyone,

I am looking for a way/hack to make some common template tags optional for some customers.

Eg. I have [COMPANY_FULL_ADDRESS] enabled for all campaign templates (screen shot attached), but will like to disable it for a single customer.

Any ideas on how to achieve this will be appreciated.
 

Attachments

  • screenshot-engage.com 2016-05-04 11-45-30.png
    screenshot-engage.com 2016-05-04 11-45-30.png
    38.1 KB · Views: 11
@Yomiit - unfortunately those tags do apply for all customers...
But you can do it from an extension like so:
PHP:
Yii::app()->hooks->addFilter('campaign_template_available_option_tags_list', function($tags, $model){
      $customerID = 1;
      if ( !empty($model->campaign_id) && !empty($model->campaign) && !empty($model->campaign->customer_id) && $model->campaign->customer_id == $customerID ) {
          foreach ($tags as $index => $optionTagInfo) {
              if (!isset($optionTagInfo['tag'], $optionTagInfo['required'])) {
                  continue;
              }
              if ($optionTagInfo['tag'] == '[COMPANY_FULL_ADDRESS]') {
                  $tags[$index]['required'] = false;
                  break;
              }
          }
      }
      return $tags;
});
And in order for this to work, you'll have to unzip and put resulted file into apps/common/models folder since it contains the new 'campaign_template_available_option_tags_list' filter hook where the above code hooks into.

Hope it helps...
 

Attachments

  • CampaignTemplate.php.zip
    2.6 KB · Views: 3
@twisted1919 thanks for the speedy response.

I ran a diff on my 1.3.6.0 version and can see a similar filter hook exist, is it ok to use this new "CampaignTemplate.php" as is.

Also, I am lost where to add the above piece of code as an extension. I guess I will also need to change "$customerID = 1" to reflect the customer's ID?

Code:
167a168
>             array('tag' => '[CURRENT_MONTH_FULL_NAME]', 'required' => false),
185a187,189
>             array('tag' => '[CAMPAIGN_SEND_AT]', 'required' => false),
>             array('tag' => '[CAMPAIGN_STARTED_AT]', 'required' => false),
>             array('tag' => '[CAMPAIGN_DATE_ADDED]', 'required' => false),
217c221
<         $tags = (array)Yii::app()->hooks->applyFilters('campaign_template_available_tags_list', $tags);
---
>         $tags = (array)Yii::app()->hooks->applyFilters('campaign_template_available_tags_list', $tags, $this);
219a224,227
>       
>         // since 1.3.6.3
>         $optionTags = (array)Yii::app()->hooks->applyFilters('campaign_template_available_option_tags_list', $optionTags, $this);
>
Diff output Note: < is from version 1.3.6.0
 
@Yomiit - First, you should really keep the app updated, 1.3.6.2 is latest version.
Now, the hook that you see in the diff, campaign_template_available_tags_list existed, i have added campaign_template_available_option_tags_list now in the new file, so make sure you upload the file.

Related to extension, here, i made one for you. Download it, extract it, edit the ConditionalCampaignTagsExt.php file and change the $customerID variable with the right customer id.
Then upload the extension folder in apps/extensions folder(or zip it and upload it from the web interface), then enable it.
 

Attachments

  • conditional-campaign-tags.zip
    2.2 KB · Views: 7
@twisted1919 I have updated the code with $customerID to corresponding customer and applied the hook via Extension upload but it is not working. Not sure what I'm missing or check.

N.B. I have also upgraded to 1.3.6.2
 
@Yomiit - the file ConditionalCampaignTagsExt.php should be inside a folder called conditional-campaign-tags and that folder should be in apps/extensions folder.

apps/extensions/conditional-campaign-tags/ConditionalCampaignTagsExt.php
 
@Yomiit - my bad, here's how the run method should look like:
Code:
public function run()
    {
        Yii::app()->hooks->addFilter('campaign_template_available_option_tags_list', function($tags, $model) {
              $customerID = 1; // edit this.
              if ( !empty($model->campaign_id) && !empty($model->campaign) && !empty($model->campaign->customer_id) && $model->campaign->customer_id == $customerID ) {
                  if (empty($tags)) {
                      $tags = array(
                          array('tag' => '[COMPANY_FULL_ADDRESS]', 'required' => false),
                      );
                  }
                  foreach ($tags as $index => $optionTagInfo) {
                      if (!isset($optionTagInfo['tag'], $optionTagInfo['required'])) {
                          continue;
                      }
                      if ($optionTagInfo['tag'] == '[COMPANY_FULL_ADDRESS]') {
                          $tags[$index]['required'] = false;
                          break;
                      }
                  }
              }
              return $tags;
        });
    }
Tested like so and it works.

It will work without the above changes too, but you'll have to save the template tags from /backend/index.php/settings/campaigns/template-tags so that the tags array get populated.
 
@twisted1919 Another suggestion here : It's really nice if either [UNSUBSCRIBE_URL] OR [DIRECT_UNSUBSCRIBE_URL] is necessary if [UNSUBSCRIBE_URL] is set as required. Usually people are afraid to input their email id on frontend to unsubscribe and that should be why I see more clicks on [UNSUBSCRIBE_URL] but less actual unsubscribes. But if we put the latter link, system will still demand for the first one to be present.
 
@twisted1919 Another suggestion here : It's really nice if either [UNSUBSCRIBE_URL] OR [DIRECT_UNSUBSCRIBE_URL] is necessary if [UNSUBSCRIBE_URL] is set as required. Usually people are afraid to input their email id on frontend to unsubscribe and that should be why I see more clicks on [UNSUBSCRIBE_URL] but less actual unsubscribes. But if we put the latter link, system will still demand for the first one to be present.
Seconded, and perhaps improvable with logic incl [UPDATE_PROFILE_URL] as the preferred gentle option (to not lose subscribers).
 
  • Like
Reactions: VVT
@twisted1919 it works with the updated code now. Many thanks for your speedy responses.

I modified 2 lines in the code in case I have another customer who may have similar needs, it works - what do you think?

Code:
// $customerID = 1;
              $customerID = array (10, 11, 12);
              //if ( !empty($model->campaign_id) && !empty($model->campaign) && !empty($model->campaign->customer_id) && $model->campaign->customer_id == $customerID ) {
              if ( !empty($model->campaign_id) && !empty($model->campaign) && !empty($model->campaign->customer_id) && in_array($model->campaign->customer_id, $customerID) ) {

Added a new license + extra 6 month support as a little token:rolleyes: of appreciation.
 
@Yomiit - yes, the in_array() solution will work just fine ;) thanks for the license too ;)
@VVT - Okay, implemented this.
@frm.mwz - not sure what you exactly mean, but i guess the unsubscribe and profile actions should be kept separate.
 
  • Like
Reactions: VVT
@Yomiit - yes, the in_array() solution will work just fine ;) thanks for the license too ;)
@VVT - Okay, implemented this.
@frm.mwz - not sure what you exactly mean, but i guess the unsubscribe and profile actions should be kept separate.
Yes, kept separate as tags.
So one can have two links under the email, as many do since years, one unsub, another update profile.
And many have come to put the same url onto both descriptions.

There are major problems with one click unsubscribes:
a forwarded email can easily be used to unsubscribe the original recipient...that's why there is confirmed opt-out...
 
@Yomiit - yes, the in_array() solution will work just fine ;) thanks for the license too ;)
@VVT - Okay, implemented this.
@frm.mwz - not sure what you exactly mean, but i guess the unsubscribe and profile actions should be kept separate.
Thanks for that, added one more license and 12 months subscription for all your considerations these days :D
 
Back
Top