track distinct email submit forms

This commit is contained in:
Jeremy Kauffman 2016-03-02 21:14:26 -05:00
parent 31e77d25b1
commit 89d9940ba4
5 changed files with 60 additions and 30 deletions

View file

@ -8,7 +8,10 @@
class Session class Session
{ {
const KEY_MAILCHIMP_LIST_IDS = 'mailchimp_list_ids', const KEY_MAILCHIMP_LIST_IDS = 'mailchimp_list_ids',
KEY_LIST_SUB_SUCCESS = 'list_success'; KEY_LIST_SUB_ERROR = 'list_error',
KEY_LIST_SUB_SIGNATURE = 'list_sub_sig',
KEY_LIST_SUB_SUCCESS = 'list_success',
KEY_LIST_SUB_FB_EVENT = 'list_sub_fb_event';
public static function init() public static function init()
{ {

View file

@ -17,6 +17,10 @@ class ContentActions extends Actions
public static function executeGet() public static function executeGet()
{ {
if (isset($_GET['email']) && $_GET['email'] && Session::get(Session::KEY_LIST_SUB_ERROR))
{
Controller::redirect('/get');
}
return ['page/get', [ return ['page/get', [
'isSubscribed' => $_GET['email'] || in_array(Mailchimp::LIST_GENERAL_ID, Session::get(Session::KEY_MAILCHIMP_LIST_IDS, [])) 'isSubscribed' => $_GET['email'] || in_array(Mailchimp::LIST_GENERAL_ID, Session::get(Session::KEY_MAILCHIMP_LIST_IDS, []))
]]; ]];

View file

@ -16,6 +16,8 @@ class MailActions extends Actions
Controller::redirect($nextUrl); Controller::redirect($nextUrl);
} }
Session::set(Session::KEY_LIST_SUB_SIGNATURE, isset($_POST['listSig']) ? $_POST['listSig'] : true);
$email = $_POST['email']; $email = $_POST['email'];
if (!$email|| !filter_var($email, FILTER_VALIDATE_EMAIL)) if (!$email|| !filter_var($email, FILTER_VALIDATE_EMAIL))
{ {
@ -34,7 +36,8 @@ class MailActions extends Actions
if ($success) if ($success)
{ {
Session::set(Session::KEY_MAILCHIMP_LIST_IDS, array_merge(Session::get(Session::KEY_MAILCHIMP_LIST_IDS, []), [$mcListId])); Session::set(Session::KEY_MAILCHIMP_LIST_IDS, array_merge(Session::get(Session::KEY_MAILCHIMP_LIST_IDS, []), [$mcListId]));
Session::set(Session::KEY_LIST_SUB_SUCCESS, __('Great success! Welcome to LBRY.')); Session::set(Session::KEY_LIST_SUB_SUCCESS, true);
Session::set(Session::KEY_LIST_SUB_FB_EVENT, isset($_POST['fbEvent']) ? $_POST['fbEvent'] : null);
} }
else else
{ {
@ -48,11 +51,24 @@ class MailActions extends Actions
public static function prepareJoinList(array $vars) public static function prepareJoinList(array $vars)
{ {
$vars['listSig'] = md5(serialize($vars));
$vars += ['btnClass' => 'btn-primary', 'returnUrl' => $_SERVER['REQUEST_URI']]; $vars += ['btnClass' => 'btn-primary', 'returnUrl' => $_SERVER['REQUEST_URI']];
$vars['error'] = Session::get('list_error');
$vars['success'] = Session::get(Session::KEY_LIST_SUB_SUCCESS); if (Session::get(Session::KEY_LIST_SUB_SIGNATURE) == $vars['listSig'])
Session::unsetKey('list_error'); {
Session::unsetKey(Session::KEY_LIST_SUB_SUCCESS); $vars['error'] = Session::get('list_error');
Session::unsetKey('list_error');
$vars['success'] = Session::get(Session::KEY_LIST_SUB_SUCCESS) ? __('Great success! Welcome to LBRY.') : false;
$vars['fbEvent'] = Session::get(Session::KEY_LIST_SUB_FB_EVENT) ?: 'Lead';
Session::unsetKey(Session::KEY_LIST_SUB_SUCCESS);
Session::unsetKey(Session::KEY_LIST_SUB_FB_EVENT);
}
else
{
$vars['success'] = false;
}
return $vars; return $vars;
} }

View file

@ -5,23 +5,29 @@
<?php js_start() ?> <?php js_start() ?>
ga('send', 'event', 'Sign Up', 'Join List', '<?php echo $listId ?>'); ga('send', 'event', 'Sign Up', 'Join List', '<?php echo $listId ?>');
twttr.conversion.trackPid('nty1x'); twttr.conversion.trackPid('nty1x');
fbq('track', "Lead"); fbq('track', <?php echo $fbEvent ?>);
<?php js_end() ?> <?php js_end() ?>
<div class="notice notice-success spacer1"><?php echo $success ?></div> <div class="notice notice-success spacer1"><?php echo $success ?></div>
<?php endif ?> <?php endif ?>
<div class="mail-submit"> <?php if ($error || !$success): ?>
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?>"/> <div class="mail-submit">
<input type="hidden" name="listId" value="<?php echo $listId ?>"/> <input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?>"/>
<input type="email" value="" name="email" class="required email standard" placeholder="someone@somewhere.com"> <input type="hidden" name="listId" value="<?php echo $listId ?>"/>
<input type="submit" value="<?php echo isset($submitLabel) ? $submitLabel : 'Subscribe' ?>" name="subscribe" id="mc-embedded-subscribe" class="<?php echo $btnClass ?>"> <input type="hidden" name="listSig" value="<?php echo $listSig ?>"/>
<?php if (isset($mergeFields)): ?> <input type="email" value="" name="email" class="required email standard" placeholder="someone@somewhere.com">
<input type="hidden" name="mergeFields" value="<?php echo htmlentities(serialize($mergeFields)) ?>" /> <input type="submit" value="<?php echo isset($submitLabel) ? $submitLabel : 'Subscribe' ?>" name="subscribe" id="mc-embedded-subscribe" class="<?php echo $btnClass ?>">
<?php endif ?> <?php if (isset($fbEvent)): ?>
<?php if (isset($meta) && $meta): ?> <input type="hidden" name="fbEvent" value="<?php echo $fbEvent ?>" />
<div class="meta"> <?php endif ?>
<?php echo __('You will receive 1-2 messages a month, only from LBRY, Inc. and only about LBRY.') ?> <?php if (isset($mergeFields)): ?>
<?php echo __('You can easily unsubscribe at any time.') ?> <input type="hidden" name="mergeFields" value="<?php echo htmlentities(serialize($mergeFields)) ?>" />
</div> <?php endif ?>
<?php endif ?> <?php if (isset($meta) && $meta): ?>
</div> <div class="meta">
<?php echo __('You will receive 1-2 messages a month, only from LBRY, Inc. and only about LBRY.') ?>
<?php echo __('You can easily unsubscribe at any time.') ?>
</div>
<?php endif ?>
</div>
<?php endif ?>
</form> </form>

View file

@ -28,15 +28,16 @@
</div> </div>
<h1><?php echo __('I am a Linux or OS X user comfortable from the command line.') ?></h1> <h1><?php echo __('I am a Linux or OS X user comfortable from the command line.') ?></h1>
<p class="pflow">Earn early adopter rewards and interact directly with developers via our Alpha client.</p> <p class="pflow">Earn early adopter rewards and interact directly with developers via our Alpha client.</p>
<div class="spacer1">
<?php echo View::render('mail/joinList', [
'submitLabel' => 'Go',
'listId' => Mailchimp::LIST_GENERAL_ID,
'mergeFields' => ['CLI' => 'Yes'],
'fbEvent' => 'Alpha',
'returnUrl' => '/get?email=1'
]) ?>
</div>
<?php if (!$isSubscribed): ?> <?php if (!$isSubscribed): ?>
<div class="spacer1">
<?php echo View::render('mail/joinList', [
'submitLabel' => 'Go',
'listId' => Mailchimp::LIST_GENERAL_ID,
'mergeFields' => ['CLI' => 'Yes'],
'returnUrl' => '/get?email=1'
]) ?>
</div>
<div class="meta"> <div class="meta">
Already signed up or really hate sharing your email? <a href="/get?email=1" class="link-primary">Click here.</a> Already signed up or really hate sharing your email? <a href="/get?email=1" class="link-primary">Click here.</a>
</div> </div>