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

problems with options #4

Open
romannl opened this issue Nov 12, 2019 · 2 comments · May be fixed by #8
Open

problems with options #4

romannl opened this issue Nov 12, 2019 · 2 comments · May be fixed by #8

Comments

@romannl
Copy link

romannl commented Nov 12, 2019

Hi Sir, I also found problems with options section in:
/classes/utils.php

Primarily with buildAnalyticsOptions functions


    protected static function buildAnalyticsOptions(Config $config): string
    {
        $options = [];

        if ($config->get('plugins.google-analytics.anonymize_ip', true)) {
            // The button by default is disabled!! so either negate the condition or set the value to true
            // $options['anonymize_ip'] = false;
            // I think setting true is better, more consistent with the variable name
            $options['anonymize_ip'] = true;
        }

There is also a problem with empty $options, since json_encode() returns empty brackets [] instead of empty value
Also you are replacing wrong quotes, we should care about single quotes, since double quotes are treated well with json_encode

    // current return value is [] if array is empty
    return str_replace('"', '\'', json_encode($options));

    // proposed, we return empty string if array is empty
    return str_replace("'", '\'', empty($options) ? '' : json_encode($options));
}
@mminer237
Copy link

This issue does totally prevent Google Analytics from registering any page views. My first instinct was to just check for a string of [], but your way makes more sense. I copied that as a pull request.

@romannl
Copy link
Author

romannl commented Nov 8, 2021

Thank you for including it! (finally :)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants