Skip to content

Commit

Permalink
Merge pull request #56 from mautic/feature/track-logged-user
Browse files Browse the repository at this point in the history
WIP: Add extra information when logged user tracking is enabled.
  • Loading branch information
shulard authored Jul 19, 2017
2 parents 370b29e + 8313688 commit d2e2f16
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion wpmautic.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function wpmautic_option( $option, $default = null ) {
return ! isset( $options[ $option ] ) ? 'header' : $options[ $option ];
case 'fallback_activated':
return isset( $options[ $option ] ) ? (bool) $options[ $option ] : true;
case 'track_logged_user':
return isset( $options[ $option ] ) ? (bool) $options[ $option ] : false;
default:
if ( ! isset( $options[ $option ] ) ) {
if ( isset( $default ) ) {
Expand Down Expand Up @@ -192,7 +194,7 @@ function wpmautic_get_url_query() {
* @return array
*/
function wpmautic_get_tracking_attributes() {
$attrs = array();
$attrs = wpmautic_get_user_query();

/**
* Update / add data to be send withing Mautic tracker
Expand All @@ -206,3 +208,32 @@ function wpmautic_get_tracking_attributes() {
*/
return apply_filters( 'wpmautic_tracking_attributes', $attrs );
}

/**
* Extract logged user informations to be send within Mautic tracker
*
* @return array
*/
function wpmautic_get_user_query() {
$attrs = array();

if (
true === wpmautic_option( 'track_logged_user', false ) &&
is_user_logged_in()
) {
$current_user = wp_get_current_user();
$attrs['email'] = $current_user->user_email;
$attrs['firstname'] = $current_user->user_firstname;
$attrs['lastname'] = $current_user->user_lastname;

// Following Mautic fields has to be created manually and the fields must match these names.
$attrs['wp_user'] = $current_user->user_login;
$attrs['wp_alias'] = $current_user->display_name;
$attrs['wp_registration_date'] = date(
'Y-m-d',
strtotime( $current_user->user_registered )
);
}

return $attrs;
}

0 comments on commit d2e2f16

Please sign in to comment.