Ming
Ming

Reputation: 784

Can you pass a custom variable into Google Analytics event tracking?

In Google Analytics, you can track events like this:

$(document).on('click', '#home .post', function() {
    ga('send', 'event', 'Home', 'click', 'Posts', '4');
}); 

What I'm wondering is if I can, instead of '4', pass a variable like this:

$(document).on('click', '#home .post', function() {
    var index = $(this).index() + 1;
    var indexStr = '' + index;
    ga('send', 'event', 'Home', 'click', 'Posts', indexStr);
});

If it does, I'm also wondering if it is necessary for me to convert it to string.

Upvotes: 0

Views: 1624

Answers (1)

Ming
Ming

Reputation: 784

Yes, yes you can pass a custom variable in Google Analytics.

Upvotes: 1

Related Questions