user2933765
user2933765

Reputation: 31

Twitter follow button - need to track universal google analytics

I am having a twitter tweet button, I am using knockout js, how can I track the number of events using universal google analytics?

<a href="https://twitter.com/share" class="twitter-share-button" data-bind="attr: { 'data-text': vote}" data-count="none">Tweet</a>

I have the below script in my knockout js which is not working

$('.is-voting-complete').on('click', '.twitter-share-button', function () {
    gaTracker.send('event', 'Social', 'Twitter', 'Tweet');
});

I am guessing there is a iframe which twitter is incorporating , because of which the on click is not firing. can somebody please help me with this

Upvotes: 1

Views: 797

Answers (1)

rolandsaven
rolandsaven

Reputation: 153

twittr is not defined because you have not included Twitters's widget.js. You should include the following before the closing body tag.

 <script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>

you can create a button like this

<a class="tw" target="_blank" href="https://twitter.com/intent/tweet? text=Check%20this%20out&amp;related=episod&amp;url=TheUrl"></a>

then bind google analytics function to the tweet event

twttr.ready(function (twttr) {
 twttr.events.bind('tweet', function(e){
  if(!e) return;
  ga('send', 'social', 'twitter', 'tweet', theURL);
 }
});

I have created a plugin called gasotracker. It works with twitter, but you are able to track other social events on your site.

Upvotes: 2

Related Questions