Using CustomJsFunctionVariable 2 or more


(jskim) #1

Hello.

When tag references CustomJsFunctionVariable
The problem at which the last CustomJsFunctionVariable is executed.

TAG(trigger : pageview)
image

Variables

  • Custom JavaScript1
    function () { return “Custom JavaScript1”; }
  • Custom JavaScript2
    function () { return “Custom JavaScript2”; }

Result : Custom JavaScript2

I would appreciate your advice if I make a mistake.
Thank you.


#2

Hi there, not quite sure what you mean? Any chance you could export your container and post it here or send it to us by email? hello at matomo org


(jskim) #3

The problem is that other variables of the same type(custom java) are executed, not the one specified by the tag.

The result I want is ‘Custom Javascript1’
But the result is ‘Custom Javascript2’.

Do you understand?


#4

Not 100% since we’re not seeing all tags etc here. Do you also use var mmInfo = in the other tags? Because that would be a global variable and overwritten by JavaScript2 I suppose.


(jskim) #5

No. I use only one tag.


#6

Any chance you could send us the exported container? Make sure that the variables “Custom JavaScript 1” and “2” return the correct value and no numbers are maybe accidentally swapped. To debug the issue we would otherwise need an exported container. You can do this by clicking on “Versions” and there is an export feature.


(jskim) #7

FYI.

{
  "idcontainer": "ME8UA37Z",
  "idsite": 1,
  "context": "web",
  "name": "test",
  "description": "",
  "created_date": "2019-01-16 01:57:05",
  "updated_date": "2019-01-16 01:57:05",
  "created_date_pretty": "Jan 16, 2019 10:57:05",
  "updated_date_pretty": "Jan 16, 2019 10:57:05",
  "revision": 1,
  "version": {
    "name": "test",
    "description": "",
    "revision": 1,
    "created_date": "2019-01-16 02:04:05",
    "created_date_pretty": "Jan 16, 2019 11:04:05",
    "updated_date": "2019-01-16 02:04:05",
    "updated_date_pretty": "Jan 16, 2019 11:04:05"
  },
  "tags": [
    {
      "idtag": 30,
      "type": "CustomHtml",
      "name": "Custom HTML",
      "parameters": {
        "customHtml": "<script type=\"text/javascript\">\n var mminfo = {{Custom JavaScript1}};\n console.log(mminfo);\n</script>",
        "htmlPosition": "bodyEnd"
      },
      "fire_trigger_ids": [
        39
      ],
      "block_trigger_ids": [],
      "fire_limit": "unlimited",
      "priority": "999",
      "fire_delay": "0",
      "start_date": null,
      "end_date": null,
      "created_date": "2019-01-16 02:04:05",
      "updated_date": "2019-01-16 02:04:05",
      "created_date_pretty": "Jan 16, 2019 11:04:05",
      "updated_date_pretty": "Jan 16, 2019 11:04:05"
    }
  ],
  "triggers": [
    {
      "idtrigger": 39,
      "type": "DomReady",
      "name": "DOM Ready",
      "parameters": [],
      "conditions": [],
      "created_date": "2019-01-16 02:04:05",
      "updated_date": "2019-01-16 02:04:05",
      "created_date_pretty": "Jan 16, 2019 11:04:05",
      "updated_date_pretty": "Jan 16, 2019 11:04:05"
    }
  ],
  "variables": [
    {
      "idvariable": 158,
      "type": "CustomJsFunction",
      "name": "Custom JavaScript1",
      "parameters": {
        "jsFunction": "function () { return \"Custom JavaScript1\"; }"
      },
      "lookup_table": [],
      "default_value": "",
      "created_date": "2019-01-16 02:04:05",
      "updated_date": "2019-01-16 02:04:05",
      "created_date_pretty": "Jan 16, 2019 11:04:05",
      "updated_date_pretty": "Jan 16, 2019 11:04:05"
    },
    {
      "idvariable": 159,
      "type": "CustomJsFunction",
      "name": "Custom JavaScript2",
      "parameters": {
        "jsFunction": "function () { return \"Custom JavaScript2\"; }"
      },
      "lookup_table": [],
      "default_value": "",
      "created_date": "2019-01-16 02:04:05",
      "updated_date": "2019-01-16 02:04:05",
      "created_date_pretty": "Jan 16, 2019 11:04:05",
      "updated_date_pretty": "Jan 16, 2019 11:04:05"
    }
  ]
}

Thanks very much for your time and help!


#8

Thanks for this. This is a bug indeed and I will need to investigate how to fix this. it’s not quite trivial unfortunately. I’ve created an issue here: Custom JS Function isn’t working when using multiple custom functions · Issue #148 · matomo-org/tag-manager · GitHub


#9

The fix will be in Matomo 3.9

If you want you can already patch this file now to make it work in case you self host Matomo: Fix JS Function Variable needs to generate one template per variable by tsteur · Pull Request #149 · matomo-org/tag-manager · GitHub


(jskim) #10

Thank you for your help. :slight_smile: