feat: xxbb
This commit is contained in:
@@ -274,26 +274,34 @@ class IngestService
|
||||
}
|
||||
|
||||
/**
|
||||
* Latest iptj/pixel visit from this IP in the last N minutes whose
|
||||
* channel_id is a new-builder channel, and no device from this IP has
|
||||
* already claimed that channel.
|
||||
* Latest iptj/pixel visit in the last N minutes whose channel_id is a
|
||||
* new-builder channel, and no device from this client IP has already
|
||||
* claimed that channel. Same IPv4 / IPv4-mapped IPv6 is preferred;
|
||||
* otherwise a recent visit still matches across address families
|
||||
* (Safari iptj is often v4, native /event often v6).
|
||||
*
|
||||
* @return array{channel_id: ?string, source_domain: ?string}
|
||||
*/
|
||||
private function matchNewBuilderVisit(?string $ip): array
|
||||
{
|
||||
$ip = is_string($ip) ? trim($ip) : '';
|
||||
$ip = PageVisit::normalizeIp($ip);
|
||||
if ($ip === '') {
|
||||
return ['channel_id' => null, 'source_domain' => null];
|
||||
}
|
||||
$minutes = max(1, (int) config('coruna.xxbb.visit_match_minutes', 30));
|
||||
$visits = PageVisit::query()
|
||||
->where('ip', $ip)
|
||||
->where('created_at', '>=', now()->subMinutes($minutes))
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
if ($visits->isEmpty()) {
|
||||
return ['channel_id' => null, 'source_domain' => null];
|
||||
}
|
||||
|
||||
foreach ($visits as $visit) {
|
||||
$ipKeys = PageVisit::ipLookupKeys($ip);
|
||||
$sameIp = $visits->filter(
|
||||
static fn (PageVisit $visit) => in_array(PageVisit::normalizeIp($visit->ip), $ipKeys, true)
|
||||
);
|
||||
foreach ($sameIp->concat($visits->diff($sameIp)) as $visit) {
|
||||
$code = Channel::normalizeNewChannelId((string) ($visit->channel_id ?? ''));
|
||||
if ($code === null) {
|
||||
continue;
|
||||
@@ -306,8 +314,8 @@ class IngestService
|
||||
continue;
|
||||
}
|
||||
$claimed = Device::query()
|
||||
->where('ip', $ip)
|
||||
->where('channel_id', $code)
|
||||
->whereIn('ip', $ipKeys)
|
||||
->exists();
|
||||
if ($claimed) {
|
||||
continue;
|
||||
@@ -331,7 +339,7 @@ class IngestService
|
||||
$attr = $this->resolveChannelAttribution($request, $payload, $allowOldC);
|
||||
$attrs = [
|
||||
'device_id' => $deviceKey,
|
||||
'ip' => $request->ip(),
|
||||
'ip' => PageVisit::normalizeIp((string) $request->ip()) ?: $request->ip(),
|
||||
'device_model' => $this->extractDeviceModel($payload),
|
||||
'ios_version' => $this->extractIosVersion($payload),
|
||||
'channel_id' => $attr['channel_id'],
|
||||
|
||||
Reference in New Issue
Block a user