shetabit / visitor

a laravel package to work with visitors and retrieve their informations
MIT License
522 stars 68 forks source link

duplicate logs #22

Open miladbrave opened 3 years ago

miladbrave commented 3 years ago

How can duplicate logs be prevented? For example if a person refresh several time in a page system add new log so it causes misinformation!!

khanzadimahdi commented 3 years ago

please add this feature to the package and send a pull request. I will merge it.

salawu commented 2 years ago

Good morning dear friend,

I see that there are duplicates. Were you able to fix this bug? If so, tell us how to fix the link. Thanks ! Good morning dear friend,

I see that there are duplicates. Were you able to fix this bug? If so, tell us how to fix the link. Thanks !

Bonjour cher ami,

Je constate qu'il y a des doublons. Avez-vous pu corriger ce bug? Si oui, dites-nous comment procéder pour corriger le lien. Merci!

salawu commented 2 years ago

Good morning dear friend,

I see that there are duplicates. Were you able to fix this bug? If so, tell us how to fix the link. Thanks !

gagaltotal commented 1 month ago

wtf, I tried writing code in visitor but it doesn't affect it at all, it can still duplicate logs

example in file Visitor.php :

public function visit(Model $model = null)
    {
        if (in_array($this->request->path(), $this->except)) {
            return;
        }

        $data = $this->prepareLog();

        // Check for existing log to prevent duplicates
        $existingVisit = Visit::where('ip', $data['ip'])
            ->where('url', $data['url'])
            ->where('device', $data['device'])
            ->where('platform', $data['platform'])
            ->first();

        if ($existingVisit) {
            return $existingVisit;
        }

        if (null !== $model && method_exists($model, 'visitLogs')) {
            $visit = $model->visitLogs()->create($data);
        } else {
            $visit = Visit::create($data);
        }

        return $visit;
    }

why ?

gagaltotal commented 1 month ago

If you want no duplication, I have tried using if logic, and bringing in a model or you can use a query builder

example code in file home your website :

    $visit = ViewPage::where('ip', $request->ip())->count(); // Check for existing log to prevent duplicates

    if ($visit >= 1) {
        return view(getTheme('home'));
    }else{
    visitor()->visit(); // create a visit log
    return view(getTheme('home'));
}

I think editing the file in /shetabit/src/Visitor.php

You can change the log to not duplicate it, but it's still the code example that I showed above