pluf2

pluf2 Commit Details


Date:2010-04-11 10:37:18 (14 years 8 months ago)
Author:Loic d'Anterroches
Branch:master
Commit:48dd53abe15cc80bdc5042ff0150aad2b660ec1b
Parents: b12a3ad33fd1564c02f70ee7af8c48e28e45a9b5
Message:Made the funnel analysis more robust against missing steps and funky in/out entries of visitors.

Changes:

File differences

src/Pluf/AB/Funnel.php
128128
129129
130130
131
132
133
131134
132135
133136
137
134138
135139
136140
137
138
139
140141
141142
142143
......
146147
147148
148149
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
150170
151171
152
153
154
155
156
157
158
159
172
173
174
175
160176
161
162
163
164
177
178
165179
166180
167181
......
180194
181195
182196
183
197
184198
185199
186200
......
191205
192206
193207
208
194209
195210
211
212
213
214
215
196216
197217
198218
// will be very easy to adapt.
foreach ($db->funnellogs->find($q) as $log) {
if (!isset($uids[$log['u'].'##'.$log['s']])) {
if ($prop and !isset($log['p'][$prop])) {
continue;
}
$uids[$log['u'].'##'.$log['s']] = true;
$step = $log['s'];
$steps[$step]['name'] = $log['sn'];
$steps[$step]['id'] = $log['s'];
if ($prop and !isset($steps[$step]['props'])) {
$steps[$step]['props'] = array();
}
if ($prop and !isset($log['p'][$prop])) {
continue;
}
$steps[$step]['total'] = (isset($steps[$step]['total'])) ?
$steps[$step]['total'] + 1 : 1;
if ($prop) {
}
}
// Now, compile the stats for steps 2 to n
if (!isset($steps[1]['total'])) {
// First, we find the "max" for the reference number of
// visitors along this funnel. This is $t1 and $tprops[prop]
$t1 = 0;
foreach ($steps as $step) {
if (isset($step['total']) and $step['total'] > $t1) {
$t1 = $step['total'];
}
if ($prop and isset($step['props'])) {
foreach ($step['props'] as $v => $t) {
if (!isset($tprops[$v])) {
$tprops[$v] = $t;
continue;
}
if ($tprops[$v] < $t) {
$tprops[$v] = $t;
}
}
}
}
if ($t1 == 0) {
return array();
}
$t1 = $steps[1]['total'];
$tprops = array();
if (isset($steps[1]['props'])) {
foreach ($steps[1]['props'] as $v => $t) {
$tprops[$v] = $t;
// some properties are set only in the
// middle of the funnel, we get the
// value in the step.
$prev_step = null;
for ($i=1;$i<=20;$i++) {
if ($prev_step == null) {
}
}
for ($i=2;$i<=20;$i++) {
if ($steps[$i] and $steps[$i-1]) {
$tp = $steps[$i-1]['total'];
if ($steps[$i]) {
$tp = $prev_step['total'];
$tn = $steps[$i]['total'];
if ($tp) {
$steps[$i]['conv'] = sprintf('%01.2f%%', 100.0 - (float)($tp-$tn)/$tp*100.0);
if (!isset($tprops[$v])) {
$tprops[$v] = $t;
}
$pv = isset($steps[$i-1]['props'][$v]) ? $steps[$i-1]['props'][$v] : 0;
$pv = isset($prev_step['props'][$v]) ? $prev_step['props'][$v] : 0;
$steps[$i]['sprops'][$v] = array($t, $pv);
$steps[$i]['sprops1'][$v] = array($t, $tprops[$v]);
if ($pv) {
$steps[$i]['sprops1'][$v][] = round(100*(float)$t/(float)$tprops[$v],2).'%';
}
}
$prev_step = $steps[$i];
}
}
for ($i=20;$i>=1;$i--) {
if (!$steps[$i]) {
unset($steps[$i]); // We remove the inexisting steps
}
}
return $steps;
}
}
src/Pluf/Tests/Log/TestLog.php
3333
3434
3535
36
3637
3738
3839
function setUp()
{
$GLOBALS['_PX_config']['log_delayed'] = false;
Pluf_Log::$level = Pluf_Log::ALL;
Pluf_Log::$stack = array();
$this->logfile = Pluf::f('pluf_log_file',
Pluf::f('tmp_folder', '/tmp').'/pluf.log');
src/Pluf/Tests/Log/TestRemote.php
4444
4545
4646
47
48
49
4750
4851
4952
......
5457
5558
5659
60
61
62
5763
5864
5965
function testSimple()
{
if (Pluf::f('test_log_testremote', false) == false) {
return;
}
$GLOBALS['_PX_config']['log_delayed'] = true;
Pluf_Log::log('hello');
$this->assertEqual(count(Pluf_Log::$stack), 1);
function testAssertLog()
{
if (Pluf::f('test_log_testremote', false) == false) {
return;
}
Pluf_Log::activeAssert();
$GLOBALS['_PX_config']['log_delayed'] = true;
assert('Pluf_Log::alog("hello")');
src/Pluf/conf/pluf.test.php
7070
7171
7272
73
73
7474
75
7576
7677
// The reason of the db_version for MySQL is only for that.
$cfg['db_version'] = '5.0';
$cfg['db_engine'] = 'SQLite';
$cfg['pluf_ab_mongo_db'] = 'pluf_ab_test';
$cfg['simple_test_path'] = '/home/loa/Vendors/simpletest';
$cfg['cache_engine'] = 'Pluf_Cache_Memcached';
return $cfg;
src/Pluf/templates/pluf/ab/funnel.html
1818
1919
2020
21
21
22
2223
23
24
2425
2526
2627
27
28
2829
2930
3031
......
3738
3839
3940
40
41
4142
4243
4344
......
6162
6263
6364
64
65
66
65
66
67
6768
6869
69
70
71
72
73
70
71
72
73
74
75
7476
7577
7678
{assign $i=1}
{foreach $stats as $step}{if $step}
{foreach $stats as $n => $step}
{if $step}
{if $i>1}
{if $i>1 and isset($step['conv'])}
<p class="right">{$step['total']} ({$step['conv']})<span class="arrow right"></span></p>
{/if}
<h2>Step {$i}: {$step['name']}</h2>
<h2>Step {$step['id']}: {$step['name']}</h2>
</td>
<td>{if $i==1}
{if count($props)}
<input type="submit" name="s" value="Filter" />
</form>
{/if}
{elseif isset($step['props'])}{assign $stepprops = $step['sprops']}
{elseif isset($step['props']) and isset($step['sprops'])}{assign $stepprops = $step['sprops']}
<div class="stepstats">
{foreach $stepprops as $k=>$t}
{/if}<br />{assign $t = $step['total']}
{blocktrans $t}{$t} unique visitor.{plural}{$t} unique visitors.{/blocktrans}
</p>
{assign $i += 1}
{/if}{/foreach}</td></tr></table>
{if count($stats) and isset($stats[$i-1]['conv1'])}
{/if}{assign $i += 1}{/foreach}</td></tr></table>
{if count($stats) and isset($step['conv1'])}
<hr />
{assign $i = $i-1}
<p><strong>{$stats[$i]['total']}</strong> out of {$stats['1']['total']} visitors reached step {$i} of this funnel.
This is a completion rate of <strong>{$stats[$i]['conv1']}</strong>.</p>
{if count($props) and isset($stats[$i]['sprops1'])}
<div class="propsstats">{assign $stepprops = $stats[$i]['sprops1']}
<p><strong>{$step['total']}</strong> out of {*$stats['1']['total']*} visitors reached step {$step['id']} of this funnel.
This is a completion rate of <strong>{$step['conv1']}</strong>.</p>
{if count($props) and isset($step['sprops1'])}
<div class="propsstats">{assign $stepprops = $step['sprops1']}
<h2>Visitor Property {$prop} </h2>
{foreach $stepprops as $k=>$t}
<p><strong>{$k}</strong>: {assign $nn = $t[1]}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.07858s using 13 queries.