Reputation: 631
I want to add this line to my Wordpress plugin to track forms submits in Google Analytics:
onClick="ga('send', 'event', { eventCategory: 'Get Solutions',
eventAction: 'Set Reminder', eventLabel: 'Activated Reminder'});"
I implemented it like this:
$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'});">
However, I am now confronted with the following error.
´Parse error: syntax error, unexpected T_STRING in /home/test/public_html/
wp-content/plugins/schedule-reminder/plugin.php on line 70´
Thus, I am wondering how can I track form submits with Google Analytics from within my plugin code?
Thanks.
Upvotes: 0
Views: 456
Reputation: 566
You will need to escape the single-quote with a backslash, otherwise you tell PHP that the string reached the end, while it didn't.
$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\'});">';
Upvotes: 1