Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to provide a custom UserId #17

Closed
htaoufik opened this issue Jan 6, 2016 · 2 comments
Closed

Unable to provide a custom UserId #17

htaoufik opened this issue Jan 6, 2016 · 2 comments
Labels
Milestone

Comments

@htaoufik
Copy link

htaoufik commented Jan 6, 2016

Hello, In setUserId function of PiwikTracker:

How can we set the userId if

1- By default it is null ( this.userId = null; in constructor )
2- Before changing the userId value we check if the current userId is null or empty and throw an exception when it is the case.

Got this in decompiled code from nuget PiwikTracker v 2.7

public void setUserId(string userId)
{
if (userId == null)
{
this.setNewVisitorId();
}
else
{
if (string.IsNullOrEmpty(this.userId))
throw new Exception("User ID cannot be empty.");
this.userId = userId;
}
}

I think we shall replace if (string.IsNullOrEmpty(this.userId)) by if (string.IsNullOrEmpty(userId))

Sincerely.
H.T

@julienmoumne
Copy link
Member

You have found a bug thank you.

The bug is at line https://github.com/piwik/piwik-dotnet-tracker/blob/2.7.0/Piwik.Tracker/PiwikTracker.cs#L1103

            if (string.IsNullOrEmpty(this.userId)) {
                throw new Exception("User ID cannot be empty.");
            }

should be

            if (string.IsNullOrEmpty(userId)) {
                throw new Exception("User ID cannot be empty.");
            }

As in https://github.com/piwik/piwik-php-tracker/blob/1.0.1/PiwikTracker.php#L1119

        if ($userId === '') {
            throw new Exception("User ID cannot be empty.");
        }

@julienmoumne
Copy link
Member

Thanks for reporting the bug.
It has been fixed and published in version 2.8.0 : https://www.nuget.org/packages/Piwik.Tracker/2.8.0

@julienmoumne julienmoumne added this to the v2.8.1 milestone Apr 24, 2017
@julienmoumne julienmoumne changed the title setUserId Unable to provide a custom UserId Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants