0

I want to do something special I think. I need to add a html-snippet with GA-Code to a function in functions.php. To do this I thought to add this piece of code:

echo ('<div onClick="ga('send', 'event', 'will-ich-haben', 'klick', 'test-klick');">');

to this function:

// Will ich haben
add_action( 'woocommerce_product_meta_end', 'childReview' );
function childReview() {

  global $post;

  echo do_shortcode('[cl-popup size="l" btn_label="Will ich haben!" btn_bgcolor="#006982" btn_color="#ffffff" overlay_bgcolor="rgba(0,105,130,0.75)" title_textcolor="#006982" content_textcolor="#006982"]
<p align="center" style="color: #999999;"><i>' .get_the_title( $post_id ). '</i></p>
 <img style="width: 400px; height: auto; float: left;" src="' .wp_get_attachment_url ( get_post_thumbnail_id( $post->ID ) ). '"/>
 <h2>So kommst du zum Produkt:</h2>
 <ul style="margin-left: 50px;">
    <li><a href="http://www.wohngeschwister.de/kontakt/">Besuch uns am Grossneumarkt!</a></li>
    <li>Schreib uns eine E-Mail: <a href="mailto:[email protected]?subject=Interesse%20an%20' .get_the_title( $post_id ). '">[email protected]</a></li>
    <li>oder ruf uns an: <a href="tel:04046643937">040/466 439 37</a></li>
</ul>
&Uuml;brigens: Egal f&uuml;r welchen Weg du dich entscheidest, in Zusammenarbeit mit <a href="http://delivva.de/" target="_blank">delivaa </a>liefern wir dir dein Lieblingsprodukt innerhalb von 60 Minuten innerhalb Hamburgs!
[/cl-popup]');
}

I tried to simply add it but that occured an error. Do you know how to integrate it a smart way? Goal: Measure clicks on the button which is generated through the shortcode.

Huge thanks in advance, Dario

1 Answer 1

0
echo ('<div onClick="ga('send', 'event', 'will-ich-haben', 'klick', 'test-klick');">');

I haven't looked any further but as a first step, this string isn't concatenated correctly.

echo "<div onClick='ga('send', 'event', 'will-ich-haben', 'klick', 'test-klick')'></div>";
3
  • Thanks, that brought me a step further again. I started with these stuff to be honest ;-) So, I come to another modification: I tried to add ' .get_the_title( $post_id ). ' to the code, so that it is echo "<div onClick='ga('send', 'event', 'will-ich-haben', 'klick', ' .get_the_title( $post_id ). ')'>"; but that doesn't work. Do you know why? Commented Aug 10, 2016 at 9:11
  • I'm not sure, probably, I have to put some () or {} or "" before and behind .get_the_title( $post_id ). but I can't find out which one to be correct... Commented Aug 10, 2016 at 9:54
  • OK, I got it myself. I just added a variable $label and defined it by $galabel = get_the_title($post_id);. Thanks a lot that you brought me to this way :) Commented Aug 10, 2016 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.