# Function declaration not found in custom variable body

**URL:** <https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031>\
**Category:** Data collection and tags\
**Created:** [April 17, 2023, 10:00am UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031 "2023-04-17T10:00:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![XW\_Agency](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/xw_agency/32/1639_2.png) [@XW\_Agency](https://community.piwik.pro/u/XW_Agency)\
**Post date:** [April 17, 2023, 10:00am UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/1 "2023-04-17T10:00:40Z")

</div>

Hi guys,

Have any of you ever encountered this problem?

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/a/aacca5111e52fa9cc0707e80e981eb486e8a6c45.png)  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/1/12137333df346b9d3166a5154d92243e91747b8c.png)

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [April 17, 2023, 10:50am UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/2 "2023-04-17T10:50:43Z")

</div>

Hi. Did you set up any Variables in your Tag Manager? Can you show your current setup?

---

<div class="post-metadata">

**Author:** ![XW\_Agency](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/xw_agency/32/1639_2.png) [@XW\_Agency](https://community.piwik.pro/u/XW_Agency)\
**Post date:** [April 17, 2023, 12:21pm UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/3 "2023-04-17T12:21:57Z")

</div>

Hi Kuba thanks for quickly jumping on this and yes I’ve got two custom JS variables:

![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/4/484fe3854c94e3ebe3b91d6dbf849d4256d52f7e.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/8/80c86752f580c1ab2b71266fce20645800d92470.png)

Ok so it might come from these you think?

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [April 17, 2023, 3:03pm UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/4 "2023-04-17T15:03:32Z")

</div>

The first function does not look correct. How are you passing the URL? Instead of passing it as argument, you could simply define it inside the function via `{{ Page Url }}` or `window.location.href`.

---

<div class="post-metadata">

**Author:** ![XW\_Agency](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/xw_agency/32/1639_2.png) [@XW\_Agency](https://community.piwik.pro/u/XW_Agency)\
**Post date:** [April 17, 2023, 3:24pm UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/5 "2023-04-17T15:24:10Z")

</div>

Yes indeed but this pops the same issue even when passing the url straight in the function unfortunately I tried both: const matches = {{ Page Url }}.match(regex);

Here are some additional info from the console if this might help:

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/2X/b/ba1f9ebbaeb232f3b4bc33f148784438ebaeb5ec.png)

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [April 17, 2023, 3:32pm UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/6 "2023-04-17T15:32:59Z")

</div>

Just noticed one more thing. You should not define names for those functions. Use just:

```auto
function() {
 // your logic here
}

```

---

<div class="post-metadata">

**Author:** ![XW\_Agency](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/xw_agency/32/1639_2.png) [@XW\_Agency](https://community.piwik.pro/u/XW_Agency)\
**Post date:** [April 17, 2023, 4:13pm UTC](https://community.piwik.pro/t/function-declaration-not-found-in-custom-variable-body/2031/7 "2023-04-17T16:13:16Z")

</div>

Thanks Kuba, I solved the console error message for the second function by using the DOM element variable from Piwik instead of the JS function even though the function works to get rid of the error. No more errors thanks again and this topic can be closed.
