javascript - GTM Event on Content -


i can't see find answer 1 anywhere. i'm trying setup trigger , event tag in google tag manager fire whenever content present. essentially, creating simple event in google analytics product views. developer site expensive, i'd handle purely in gtm.

one piece of content exists on product pages submit on cart button.

can recommend method inject code gtm fire when content exists can trigger tag off it?

here html in , around cart button. i'm thinking can fire when class="clsaddcartright" exists or submit - either one:

    <div id="variationgroup" class="clsviewitemvariationgroup clsoverflow" style="clear:both;">     <div class="clsviewitemvariationlist clsoverflow" style="width:200px;margin:0 auto;">         <select name="item_variations" id="item_variations_496" onchange="getdetails()">             <option value="1606" selected="selected">medium</option>             <option value="1607">large</option>         </select>     </div>     <div class="clsitemsaledetailblockbottom">         <form name="purchaseitemfrm" id="purchaseitemfrm" action="http://www.runwaycrush.com/marketplace/cart.html" method="post">             <input type="hidden" name="item_id" id="item_id" value="1602">             <input type="hidden" name="c_action" id="c_action" value="add">             <input type="hidden" name="item_ref" id="item_ref" value="kanduclothing">             <input type="hidden" name="item_matrix_id" id="item_matrix_id" value="4721">                   <div class="clsitemcartblock clsfloatright" id="addcartbutton" style="margin:20px auto 0px; width:318px;">                                         <div class="clsaddcartleft">                         <div class="clsaddcartright">                             <input type="submit" name="add_to_cart" id="add_to_cart" value="add cart">                         </div>                     </div>                                     </div>         </form>     </div>         </div> 

you can use dom type variable in gtm , use "css selector" option select element classname (if same class there multiple times pick first occurence). if set attribute name field "class" value variable value of class attribute.

actually think better if use button , "id" attribute value of "add_to_cart", because ids unique per page (or should be).

however need event trigger tag.

the value available after dom has rendered. easiest way set pageview , set trigger type "dom ready" , have if fire when value of dom variable matches classname (or id respectively) of button.

however if product page urls follow recognizable pattern be lot better use url filter in pageview trigger. way have tags trigger on pageload, many tags preferable.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -