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']];
if (Session::get(Session::KEY_LIST_SUB_SIGNATURE) == $vars['listSig'])
{
$vars['error'] = Session::get('list_error'); $vars['error'] = Session::get('list_error');
$vars['success'] = Session::get(Session::KEY_LIST_SUB_SUCCESS);
Session::unsetKey('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_SUCCESS);
Session::unsetKey(Session::KEY_LIST_SUB_FB_EVENT);
}
else
{
$vars['success'] = false;
}
return $vars; return $vars;
} }

View file

@ -5,15 +5,20 @@
<?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 ?>
<?php if ($error || !$success): ?>
<div class="mail-submit"> <div class="mail-submit">
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?>"/> <input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?>"/>
<input type="hidden" name="listId" value="<?php echo $listId ?>"/> <input type="hidden" name="listId" value="<?php echo $listId ?>"/>
<input type="hidden" name="listSig" value="<?php echo $listSig ?>"/>
<input type="email" value="" name="email" class="required email standard" placeholder="someone@somewhere.com"> <input type="email" value="" name="email" class="required email standard" placeholder="someone@somewhere.com">
<input type="submit" value="<?php echo isset($submitLabel) ? $submitLabel : 'Subscribe' ?>" name="subscribe" id="mc-embedded-subscribe" class="<?php echo $btnClass ?>"> <input type="submit" value="<?php echo isset($submitLabel) ? $submitLabel : 'Subscribe' ?>" name="subscribe" id="mc-embedded-subscribe" class="<?php echo $btnClass ?>">
<?php if (isset($fbEvent)): ?>
<input type="hidden" name="fbEvent" value="<?php echo $fbEvent ?>" />
<?php endif ?>
<?php if (isset($mergeFields)): ?> <?php if (isset($mergeFields)): ?>
<input type="hidden" name="mergeFields" value="<?php echo htmlentities(serialize($mergeFields)) ?>" /> <input type="hidden" name="mergeFields" value="<?php echo htmlentities(serialize($mergeFields)) ?>" />
<?php endif ?> <?php endif ?>
@ -24,4 +29,5 @@
</div> </div>
<?php endif ?> <?php endif ?>
</div> </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>
<?php if (!$isSubscribed): ?>
<div class="spacer1"> <div class="spacer1">
<?php echo View::render('mail/joinList', [ <?php echo View::render('mail/joinList', [
'submitLabel' => 'Go', 'submitLabel' => 'Go',
'listId' => Mailchimp::LIST_GENERAL_ID, 'listId' => Mailchimp::LIST_GENERAL_ID,
'mergeFields' => ['CLI' => 'Yes'], 'mergeFields' => ['CLI' => 'Yes'],
'fbEvent' => 'Alpha',
'returnUrl' => '/get?email=1' 'returnUrl' => '/get?email=1'
]) ?> ]) ?>
</div> </div>
<?php if (!$isSubscribed): ?>
<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>