Skip Navigation

[Resolved] Adding GTM specifics to links.

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by valerieC-2 4 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1575803
annotated html.png
Screen Shot 2020-04-06 at 11.20.54 AM.png

Tell us what you are trying to do? I'm trying to add google tracking tags to specific elements in my loop.

Is there any documentation that you are following? Nope. Couldn't find any.

Is there a similar example that we can see? See attached screenshots that show my existing loop, and a modification of the current HTML that shows what I'm trying to do.

What is the link to your site? hidden link

#1577199

Hi Valerie,

Thank you for contacting us and I'd be happy to assist.

If your goal is to include "data-gtm-value" attribute to specific links in the view, you can replace:


<a href="[types field='link-to-yt' output='raw'][/types]" target="_blank" class="yt-play gtm-click-tracking" rel="noopener noreferrer">

With:


<a href="[types field='link-to-yt' output='raw'][/types]" target="_blank" class="yt-play gtm-click-tracking" rel="noopener noreferrer" data-gtm-value="[wpv-post-title output='sanitize']">

This will include "data-gtm-value" attribute with the sanitized post title as value.
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-title )

For the post's slug as value, you can use the "wpv-post-slug" shortcode instead.
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-post-slug )


<a href="[types field='link-to-yt' output='raw'][/types]" target="_blank" class="yt-play gtm-click-tracking" rel="noopener noreferrer" data-gtm-value="[wpv-post-slug]">

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1577343

That solution worked in the first instance, but I can't get it to work in the second instance (in the button group). It's being filtered out, even extra hard-coded info such as, data-gtm-value="hardcodetest", is stripped.

The first instance it is a raw output within an

Thanks for the update and glad that it worked.

Your observation is correct and since the second instance is using the tag or link generated using the types shortcode, it will need to be generated manually too, like the first one:


<a class="button gtm-click-tracking" href="[types field='link-to-lesson-plan' output='raw'][/types]" title="Lesson Plan" target="_blank" data-gtm-value="[wpv-post-title output='sanitize']"> 
....
</a>

This should do the trick.

#1582363

My issue is resolved now. Thank you!