ACF Link field with GTM event
Adds new ACF field to create links including GTM events.
★ 1stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/frontycore/acf-link-gtm/archive/refs/heads/main.zipReadme
ACF Link with GTM event Field
Custom field type for Advanced Custom Field Wordpress plugin.
This plugins adds new field type called "Link with GTM event", which works as normal link, but adds GTM event input into WP Link dialog.
Value of the GTM event input is then returned under gtm key in an array along with title, url and target.
How to work with this
-
In your WP admin under Custom fields, create a field group with new field of
Link with GTM eventtype. -
In the code of your template or plugin where you'd like to render a link HTML:
<?php
/**
* Returns somethink like:
* [
* 'title' => 'My GTM link',
* 'url' => 'https://google.com',
* 'target' => '_blank',
* 'gtm' => 'clickOnGoogle'
* ]
*/
$link = get_field('myGtmLink');
?>
<a
href="<?php echo $link['title'] ?>"
<?php if ($target = $link['target']) echo 'target="' . $target . '"' ?>
<?php if ($gtm = $link['gtm']) echo "onclick=\"dataLayer.push({'event': 'InteractionUI' 'eventCategory': 'Button','eventAction': 'Click','eventLabel': '','eventValue': '$eventValue'});\"" ?>
>
<?php echo $link['title'] ?>
</a>