matomo-org / tag-manager

Free Open Source Matomo Tag Manager - A simple way to manage and maintain all of your (third-party) tags on your website.
https://matomo.org
GNU General Public License v3.0
174 stars 58 forks source link

Event Value: "The value is not a number" when using variable #130

Closed jrpub closed 5 years ago

jrpub commented 5 years ago

Hi,

Sorry if this issue is not a bug. When I try to set a variable name as the value of an event in the tag manager, I have the error message:

Event Value: The value is not a number.

I tried with several variables (custom - for instance a constant - or a predefined one). Is this not supported or did I miss something? The weird thing is that there is the variable selector button near the "Event value", so I guess this is a supported feature.

Matomo version: 3.7.0
MySQL version: 5.7.24-0ubuntu0.18.04.1
PHP version: 7.0.32-0ubuntu0.16.04.1
tsteur commented 5 years ago

It's a bug indeed and created a fix for it.

FYI: If you find more issues, please create them in https://github.com/matomo-org/tag-manager/issues ideally. Cheers

Findus23 commented 5 years ago

@tsteur

FYI: If you find more issues, please create them in https://github.com/matomo-org/tag-manager/issues ideally.

I guess this will happen more often now that MTM is a part of Matomo.

You should be able to easily move the issue to the tag-manager repo: https://help.github.com/articles/transferring-an-issue-to-another-repository/

tsteur commented 5 years ago

👍 done

jrpub commented 5 years ago

Tested, it works to validate the form, but however I don't understand something.

I expected the same behaviour as if I put {{ScrollVerticalPercentage}} in "Event actions", where the variable is replaced on the tracked website not in Matomo.

tsteur commented 5 years ago

Once I save that, the form shows "0" (meaning that the variable is likely replaced immediately).

Where is it replaced immediately? In the create/edit form it still shows the variable name for me.

jrpub commented 5 years ago

I tried again:

screenshot_2018-11-25 tags - tag manager - matomo

I entered the variable {{RandomNumber}} for instance, then I am clicking on "Update".

Then the form is just showing 0:

screenshot_2018-11-25 tags - tag manager - matomo 1

In the database, the value is stored as 0:

screenshot_2018-11-25 websites localhost piwik piwik_tagmanager_tag phpmyadmin 4 6 6deb5

jrpub commented 5 years ago

The eventValue is correctly sent to the API:

screenshot_2018-11-25_20-31-57

EDITED: a bit more information:

$parameters['eventValue'] is still correct at the entry of the function formatParameters in Tag.php, but the returned parameters and $newParameters['eventValue'] contains 0.

private function formatParameters($tagType, $parameters)
    {
        $tagTemplate = $this->tagsProvider->getTag($tagType);

        if (empty($tagTemplate)) {
            throw new \Exception('Invalid tag type');
        }

        file_put_contents("test.txt", print_r($parameters, true)); // ADDED
        $params = $tagTemplate->getParameters();
        // we make sure to only save parameters that are defined in the tag template
        $newParameters = [];
        foreach ($params as $param) {
            if (isset($parameters[$param->getName()])) {
                $param->setValue($parameters[$param->getName()]);
                $newParameters[$param->getName()] = $param->getValue();
            } else {
                // we need to set a value to make sure that if for example a value is required, we trigger an error
                $param->setValue($param->getDefaultValue());
            }
        }
        file_put_contents("test.txt", print_r($newParameters, true), FILE_APPEND);  // ADDED
        return $newParameters;
    }

RESULTS:

more test.txt
Array
(
    [matomoConfig] => {{Matomo Configuration}}
    [trackingType] => event
    [idGoal] => 
    [eventCategory] => test
    [eventAction] => test
    [eventName] => test
    [eventValue] => {{RandomNumber}}
)
Array
(
    [matomoConfig] => {{Matomo Configuration}}
    [trackingType] => event
    [idGoal] => 
    [eventCategory] => test
    [eventAction] => test
    [eventName] => test
    [eventValue] => 0
)
tsteur commented 5 years ago

Sorry about that, I just noticed I've only applied part of the patch and not all my changes I had. Fixed it in https://github.com/matomo-org/tag-manager/commit/478e05718cb33c13f23d70d9409bbbbb4c67c88b

jrpub commented 5 years ago

Ah yes, much better! It works.

I can stop to debuging it myself :p

Many thanks!

jrpub commented 5 years ago

Not fully solved yet!

"The event value can only include numeric values and variables." when publishing the new tags.

tsteur commented 5 years ago

So sorry about that! See fix in https://github.com/matomo-org/tag-manager/pull/131 . Was very early this morning and must have forgotten to look at the tests (which I usually always do). Should be fixed now but will wait for tests to pass before merging.