在警报中嵌入谷歌转换代码


Embedding Google Conversion Code in Alert

我正在使用Avada的模板(http://theme-fusion.com/avada/contact/)以及使用他们的联系人页面。每当有人成功提交表单时,页面就会重新加载一个额外的"警报"框,其中填充有成功消息。如果可能的话,我希望在这个提醒框中嵌入一个谷歌转换像素,而不必将用户发送到一个全新的页面。创建警报框的代码是

<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<?php echo do_shortcode( '[alert type="success" accent_color="" background_color="" border_size="1px" icon="" box_shadow="yes" animation_type="0" animation_direction="down" animation_speed="0.1" class="" id=""]' .  __( 'Thank you', 'Avada' ) . ' <strong>' . $name . '</strong> ' . __( 'for contacting us! Your email was successfully sent!', 'Avada' ) . '[/alert]' ); ?>                                   
<br />
<?php } ?>

生成

<div class="fusion-alert alert success alert-dismissable alert-success alert-shadow">
    <button type="button" class="close toggle-alert" data-dismiss="alert" aria-hidden="true">&times;</button>
    <span class="alert-icon">
        <i class="fa fa-lg fa-check-circle"></i>
    </span>
    Thank you <strong>Test</strong> for contacting us! Your email was successfully sent!</div>                              
    <br />
</div>

要嵌入的代码看起来像这个

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "1";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""    src="//www.googleadservices.com/pagead/conversion/1/?label=1&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

非常感谢您的任何帮助

由于每行都有打开和关闭php标记,您可以简单地在两个php块之间粘贴html代码(但在"if"块之后)。您可以选择只使用noscript块中的image标记(转换仍将被跟踪)。

<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
// just the noscript image tag, alternatively paste the whole code here
<img height="1" width="1" style="border-style:none;" alt=""    src="//www.googleadservices.com/pagead/conversion/1/?label=1&amp;guid=ON&amp;script=0"/>
<?php 
echo do_shortcode( '[alert type="success" accent_color="" background_color="" border_size="1px" icon="" box_shadow="yes" animation_type="0" animation_direction="down" animation_speed="0.1" class="" id=""]' .  __( 'Thank you', 'Avada' ) . ' <strong>' . $name . '</strong> ' . __( 'for contacting us! Your email was successfully sent!', 'Avada' ) . '[/alert]' ); ?>                                   
<br />
<?php } ?>