I am facing an issue while trying to send Event Tracking values with labels set by variables in the code behind. Although everything renders correctly on the page, the events are not being tracked. The dynamic events are not showing up in Google Analytics under the Events section, unlike the hardcoded "Download" event.
When I attempt the following, only the initial "Download" event appears in Google Analytics:
$('#DownloadButton').on('click', function () {
var s1 = "<%= Var1 %>";
var s2 = "<%= Var2 %>";
var s3 = "<%= Var1 %> | <%= Var2 %>";
ga('send', 'event', 'button', 'click', 'Download');
//the following variable labels are not tracked in GA
ga('send', 'event', 'cat1', 'v1', s1);
ga('send', 'event', 'cat2', 'v2', s2);
ga('send', 'event', 'cat3', 'both', s3);
});
When I embed the server variables directly, only the "Download" event and Var1 are sent to GA, but not the last two:
$('#DownloadButton').on('click', function () {
ga('send', 'event', 'button', 'click', 'Download');
ga('send', 'event', 'cat1', 'v1', "<%= Var1 %>");
//the last two events are not received by GA
ga('send', 'event', 'cat2', 'v2', "<%= Var2 %>");
ga('send', 'event', 'cat3', 'both', "<%= Var1 %> | <%= Var2 %>");
});
It seems like the issue arises after encountering "<%= Var1 %>".
Var1 represents a name such as "Gala Apple" and is rendering correctly on the page:
ga('send', 'event', 'sheet', 'Side1', "Gala Apple");