Wordpress:在插件中添加Google Analytics onClick($ content)

时间:2014-09-08 11:21:10

标签: php wordpress google-analytics

我想将此行添加到我的Wordpress插件中,以跟踪Google Analytics中的表单提交:

onClick="ga('send', 'event', { eventCategory: 'Get Solutions', 
eventAction: 'Set    Reminder', eventLabel: 'Activated Reminder'});"

我实现了这样:

$content .= '<input type="submit" name="sch_submit" value="Set reminder"   
style="background:#1eaa2f" onClick="ga('send', 'event', { eventCategory: 'Get 
Solutions', eventAction: 'Set Reminder', eventLabel: 'Activated Reminder'});">

但是,我现在面临以下错误。

´Parse error: syntax error, unexpected T_STRING in /home/test/public_html/
 wp-content/plugins/schedule-reminder/plugin.php on line 70´

因此,我想知道如何在插件代码中跟踪Google Analytics的表单提交?

感谢。

1 个答案:

答案 0 :(得分:1)

您需要使用反斜杠转义单引号,否则您告诉PHP字符串到达​​结尾,而不是。

$content .= '<input type="submit" name="sch_submit" value="Set reminder"   
style="background:#1eaa2f" onClick="ga(\'send\', \'event\', { eventCategory: \'Get 
Solutions\', eventAction: \'Set Reminder\', eventLabel: \'Activated Reminder\'});">';