Skip to content

Commit

Permalink
It is not possible to record more than one conversion per second for …
Browse files Browse the repository at this point in the history
…the same visit (matomo-org#13727)

* It is not possible to record more than one conversion per second for the same visit

fix matomo-org#9916

we randomize the first 2 numbers increasing the chances to record multiple goal conversions per second per visit.

* make sure to generate mysql safe int

* Update GoalManager.php
  • Loading branch information
tsteur authored and diosmosis committed Jan 22, 2019
1 parent 01ceef6 commit 48e5531
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/Tracker/GoalManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,31 @@ protected function recordStandardGoals(VisitProperties $visitProperties, Request
}

// If multiple Goal conversions per visit, set a cache buster
$conversion['buster'] = $convertedGoal['allow_multiple'] == 0
? '0'
: $visitProperties->getProperty('visit_last_action_time');
if ($convertedGoal['allow_multiple'] == 0) {
$conversion['buster'] = 0;
} else {
$lastActionTime = $visitProperties->getProperty('visit_last_action_time');
if (empty($lastActionTime)) {
$conversion['buster'] = $this->makeRandomMySqlUnsignedInt(10);
} else {
$conversion['buster'] = $this->makeRandomMySqlUnsignedInt(2) . Common::mb_substr($visitProperties->getProperty('visit_last_action_time'), 2);
}
}

$conversionDimensions = ConversionDimension::getAllDimensions();
$conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onGoalConversion', $visitor, $action, $conversion);

$this->insertNewConversion($conversion, $visitProperties->getProperties(), $request, $action, $convertedGoal);
}
}

private function makeRandomMySqlUnsignedInt($length)
{
// mysql int unsgined max value is 4294967295 so we want to allow max 39999...
$randomInt = Common::getRandomString(1, '123');
$randomInt .= Common::getRandomString($length - 1, '0123456789');
return $randomInt;
}

/**
* Helper function used by other record* methods which will INSERT or UPDATE the conversion in the DB
Expand Down

0 comments on commit 48e5531

Please sign in to comment.