# Placement settings for custom content

**URL:** <https://community.piwik.pro/t/placement-settings-for-custom-content/314>\
**Category:** Data collection and tags\
**Created:** [October 28, 2021, 7:40am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314 "2021-10-28T07:40:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [October 28, 2021, 7:40am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/1 "2021-10-28T07:40:31Z")

</div>

Hi All - I’m trying to create a custom content tag, and I am able to get it to fire, but I can’t manage to place my custom content.

This is an attempt to target element by classname. Doesn’t work.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/0a137b20502ef5c626b6989f4970800c1929697d.png)

I’m not sure if I’m supposed to use {{double brackets}} or not. What is the expected syntax here?

Thanks!

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [October 29, 2021, 1:26pm UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/2 "2021-10-29T13:26:18Z")

</div>

Hi. You have to use ID instead of a class. [This article](https://help.piwik.pro/support/tag-manager/custom-content-tag/) should be also helpful.

---

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [October 31, 2021, 11:50am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/3 "2021-10-31T11:50:47Z")

</div>

Thanks!  
I don’t have IDs on my elements. Is there a workaround?

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/michael/32/27_2.png) [@Michael](https://community.piwik.pro/u/Michael)\
**Post date:** [November 1, 2021, 12:38am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/4 "2021-11-01T00:38:41Z")

</div>

Hi @michaelf,

One of the tricks to get around this limitation if you don’t have an ID is to earlier (e.g. on `DOM ready` event) run a separate tag to add ID to element that doesn’t have it. For example:

```auto
<script>
    document.querySelector(".myelem").setAttribute("id","some_id_of_your_choice");
</script>

```

I hope it will be helpful for you. Don’t hesitate to ask further questions if you have any. Cheers!

---

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [November 2, 2021, 7:10am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/5 "2021-11-02T07:10:03Z")

</div>

Thank you, I appreciate the clever idea 😀

Can this somehow be done solely in Piwik (Tag Manager?) or does it have to be added to application code?

Also, any plans to support the type of selectors we see elsewhere in Tag Manager? Creating custom events, for example, can be done without requiring ID’s on elements.

---

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [November 2, 2021, 7:11am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/6 "2021-11-02T07:11:44Z")

</div>

Hang on @Michael don’t take the time yet, I re-read your message and seems like you are saying that there is a way to do this with a tag. I will try and either succeed or fail and let u know!

---

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [November 2, 2021, 8:04am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/7 "2021-11-02T08:04:36Z")

</div>

OK, I see how it might be possible but was not able to get it to work.

I did run your javascript in the browser dev tools console and it worked like magic - ID was injected into target element.

Below are my trigger and tag. The tag is not showing as firing in debugger.

Can you help troubleshoot?

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/9a4e05af4ba264c30f8d29d9496c1ace3daefcf2.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/michael/32/27_2.png) [@Michael](https://community.piwik.pro/u/Michael)\
**Post date:** [November 2, 2021, 10:53am UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/8 "2021-11-02T10:53:25Z")

</div>

Hey @michaelf, thanks for the feedback!  
I see that you have “Fire tag once per session” selected in the trigger. I think this is why it might not run for you when you’re testing - it did once, and then it won’t for the time of the session. Make sure to allow “Fire tag multiple times” and check then - it should work. If not - please post a link to the page you’re testing on.

Cheers!

---

<div class="post-metadata">

**Author:** ![michaelf](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@michaelf](https://community.piwik.pro/u/michaelf)\
**Post date:** [November 2, 2021, 3:19pm UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/9 "2021-11-02T15:19:45Z")

</div>

Thanks for the idea. I changed the trigger to file multiple times. Still does not work. I saw this error however:

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

Maybe that means the custom JS in the tag couldn’t find the target element because it didn’t load into the page yet. Maybe that’s the issue?

(I can’t share a link, app is behind firewall, VPN etc)

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/michael/32/27_2.png) [@Michael](https://community.piwik.pro/u/Michael)\
**Post date:** [November 2, 2021, 4:06pm UTC](https://community.piwik.pro/t/placement-settings-for-custom-content/314/10 "2021-11-02T16:06:47Z")

</div>

Yes, that would be just the reason. Element that you want to add the ID to, is not available at the time of running the tag.

There are multiple ways to go about this:

- easy way - delay running the tags to Page Load state, but that can cause undesired flickering of the personalised element
- less-easy way - send a dataLayer event from your website when the element is rendered, and base your trigger on that dataLayer event
- hard way - employ mutationObserver to observe your site as it loads to find that given element has been already loaded, and then execute tag for adding the ID

I hope those suggestions will be useful for you. Don’t hesitate to ask further if you have any questions!
