Closed (works as designed)
Project:
Mailchimp
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Feb 2010 at 20:37 UTC
Updated:
27 Apr 2011 at 18:12 UTC
It would be nice if the site-name was an option for the Merge Variables, in case multiple websites are subscribing people to the same list and you want to segment them. I suppose you could solve this problem by making a separate Mailing List, but there are probably other use cases.
I made it happen by just adding this code to the end of mailchimp_mailchimp_merge_keys() to include the Global tokens:
<?php if (function_exists('token_get_list')) {
$tokens = token_get_list(array('global', 'order'));
if (is_array($tokens['global'])) {
foreach ($tokens['global'] as $token => $name) {
$out['token_'. $token] = t('Token: !field', array('!field' => $name));
}
}
} ?>
Another option that might have worked for me would be a "custom key" option, so I could enter the site name by hand, but the Global Tokens was a faster solution for me.
Thanks for the great module! Works like a charm and it was just what we needed.
Comments
Comment #1
Brian294 commentedI second support for global tokens (actually ALL tokens). I am the author of the Google Analytics Tokenizer module and I need to get my tasty little tokens into mail chimp. http://drupal.org/project/ga_tokenizer
The code you have proposed certainly adds the token names to the list, but there are still some problems. 1. User tokens no longer display on the list. 2. Global tokens don't get merged -- at least for me.
It appears a second function is doing the actual merging into mail chimp and "user" is hard-coded into the routine:
Comment #2
levelos commentedThe module actually exposed 2 hooks, hook_mailchimp_merge_keys() and hook_mailchimp_merge_values() so any other module can add other merge values as needed.
Comment #3
Brian294 commentedI actually tested those hooks (hook_mailchimp_merge_keys and hook_mailchimp_merge_values) and they didn't work.
Comment #4
Brian294 commentedI should probably give you some sample code to justify my fussy-ness.
Comment #5
levelos commentedNot sure w/o debugging your code. The implementation is very straightforward:
Comment #6
Brian294 commentedmailchimp_get_merge_keys will return my list of variables.
mailchimp_get_merge_values is where the problem is. It probably needs to look more like this to accomodate for non-authenticated users.
Comment #7
levelos commentedBrian - The module is actually not current designed to process merge values for anonymous users at all. The call to mailchimp_get_merge_values() is not made when an anonymous form is submitted. All merge values are taken from the form directly. If an "anonymous form" is presented to authenticated users, however, merge values are grabbed as defaults for the form fields.
So I'm not sure the point in allowing the call to mailchimp_get_merge_values() for anonymous users. You could always take the approach of using form alter to add hidden fields to the subscription form, which will then get posted as merge values to MC when it's submitted.