// add slug foreach ($formworks['forms'] as $slug => &$forms_set) { $forms_set['slug'] = $slug; foreach ($forms_set['forms'] as $form_id => $form) { // hack to populate for ($i = 0; $i < 20; $i++) { $entry = array('form_id' => $form_id, 'prefix' => $slug, 'user_id' => 1, 'user_key' => '56334b88a6dc8', 'datestamp' => date('Y-m-d H:i:s', strtotime("-" . rand(0, DAY_IN_SECONDS) . " seconds")), 'meta_key' => $types[rand(0, 8)], 'meta_value' => 1); //$wpdb->insert( 'wp_formworks_tracker', $entry ); } $list = array(); $activity_list = array(); $limit = count($activity_list); $users_query = new \WP_User_Query(array('role' => 'administrator', 'fields' => 'ID', 'number' => -1)); $admins = $users_query->get_results(); $request = array('form' => $form_id, 'prefix' => $slug, 'filters' => array('admins' => $users_query->get_results())); $forms_set['forms'][$form_id] = formworks_get_quick_stats(array(), $request); $forms_set['forms'][$form_id]['name'] = $form; $activity = $wpdb->get_results("SELECT \n\t\t\t\tCOUNT( `id` ) as `total`\n\t\t\tFROM\n\t\t\t\t`{$wpdb->prefix}formworks_tracker` \n\t\t\tWHERE \n\t\t\t\t\n\t\t\t\t`form_id` = '{$form_id}'\n\t\t\t\t&&\n\t\t\t\t`prefix` = '{$slug}'\n\n\t\t\tGROUP BY\n\t\t\tSUBSTR( `datestamp`, 1, 14) DESC\n\t\t\tORDER BY\n\t\t\t`datestamp` DESC\n\t\t\t\n\t\t\t;", ARRAY_A); foreach ($activity as $line_key => $line) { $activity_list[] = $line['total']; } $forms_set['forms'][$form_id]['activity'] = implode(',', $activity_list); } } ?> <div class="wrap formworks-calderamain-canvas" id="formworks-main-canvas"> <span class="wp-baldrick spinner" style="float: none; display: block;" data-target="#formworks-main-canvas" data-before="frmwks_canvas_reset" data-callback="frmwks_canvas_init" data-type="json" data-request="#formworks-live-config" data-event="click" data-template="#main-ui-template" data-autoload="true"></span> </div> <div class="clear"></div>
/** * Callback to create a story * * @since 1.0.0 * * @param array $data * @param array $request * * @return string */ function formworks_get_summary_story($data, $request) { global $wpdb; $stats = formworks_get_core_events($data, $request); $total_views = array_sum($stats['datasets']['view']['data']); $total_engage = array_sum($stats['datasets']['engage']['data']); $total_loads = array_sum($stats['datasets']['loaded']['data']); $total_submitions = array_sum($stats['datasets']['submission']['data']); $engage_conversion = 0; $load_conversion = 0; $view_conversion = 0; $engage_load = 0; $engage_view = 0; if ($total_engage > 0) { $engage_conversion = round($total_submitions / $total_engage * 100, 1); } if ($total_loads > 0) { $load_conversion = round($total_submitions / $total_loads * 100, 1); } if ($total_views > 0) { $view_conversion = round($total_submitions / $total_views * 100, 1); } if ($total_loads > 0 && $total_engage > 0) { $engage_load = round($total_engage / $total_loads * 100, 1); } if ($total_views > 0 && $total_engage > 0) { $engage_view = round($total_engage / $total_views * 100, 1); } // quick stats $quick_stats = formworks_get_quick_stats($data, $request); // stories $starts = array('this_week' => __('This week', 'formworks'), 'this_month' => __('This month', 'formworks'), 'last_month' => __('Last month', 'formworks'), 'custom' => sprintf(__('Between %s and %s', 'formworks'), '<strong>' . $request['filters']['date']['start'] . '</strong>', '<strong>' . $request['filters']['date']['end'] . '</strong>')); $stats['conversion_story'] = '<p>' . $starts[$request['filters']['date']['preset']] . ', '; $stats['conversion_story'] .= sprintf(_n('The form was loaded %s time ', 'The form was loaded %s times ', $total_loads, 'formworks'), '<strong>' . $total_loads . '</strong>'); $stats['conversion_story'] .= sprintf(_n('and received %s submission ', 'and received %s submissions ', $total_submitions, 'formworks'), '<strong>' . $total_submitions . '</strong>'); $stats['conversion_story'] .= sprintf(__('and was completed within a %s average', 'formworks'), '<strong>' . $quick_stats['submission']['average_time'] . '</strong>'); $stats['conversion_story'] .= '</p>'; $stats['conversion_story'] .= '<p>'; if (!empty($engage_conversion)) { if ($engage_conversion > 0) { $stats['conversion_story'] .= sprintf(__('%s of visitors actively engage the form and %s of engaging users go on to a submission. ', 'formworks'), '<strong>' . $engage_load . '%</strong>', '<strong>' . $engage_conversion . '%</strong>'); } } if (!empty($load_conversion)) { $stats['conversion_story'] .= sprintf(esc_html__('That is a conversion rate of %s from load', 'formworks'), '<strong>' . $load_conversion . '%</strong>'); if ($engage_conversion > 0) { $stats['conversion_story'] .= ' '; $stats['conversion_story'] .= sprintf(esc_html__(' with a %s abandon rate.', 'formworks'), '<strong>' . (100 - $engage_conversion) . '%</strong>'); $stats['conversion_story'] .= '<br>'; } else { $stats['conversion_story'] .= '.'; } } $stats['conversion_story'] .= '</p>'; // is hidden? if ($total_views < $total_loads) { $view_percent = round(100 - $total_views / $total_loads * 100, 1); $stats['conversion_story'] .= '<p>'; $stats['conversion_story'] .= __('There are, however, more loads than views, which indicates that the form is not visible on page load.', 'formworks'); $stats['conversion_story'] .= sprintf(esc_html__("Therefore %s of page visitors don't even see the form. ", 'formworks'), '<strong>' . $view_percent . '%</strong>'); $stats['conversion_story'] .= '</p>'; $stats['conversion_story'] .= '<p>'; if (!empty($view_conversion)) { $stats['conversion_story'] .= sprintf(esc_html__('Of those that do see the form, the conversion rate is %s. ', 'formworks'), '<strong>' . $view_conversion . '%</strong>'); } if (!empty($engage_conversion)) { if ($engage_conversion > 0) { $stats['conversion_story'] .= sprintf(esc_html__('This means that %s of visitors who see the form, actively engage it.', 'formworks'), '<strong>' . $engage_view . '%</strong>'); } } $stats['conversion_story'] .= '</p>'; } else { $stats['conversion_story'] .= '<p>'; $stats['conversion_story'] .= esc_html__('Form loads and views are the same. This indicates that the form is visible on page load.', 'formworks'); $stats['conversion_story'] .= '</p>'; } return $stats['conversion_story']; }