kriskbx / whatsapp-sharing

whatsapp sharing button + generator

Home Page:http://kriskbx.github.io/whatsapp-sharing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

whatsapp for google analytics

soumyajitcn opened this issue · comments

We added google analytics onclick code into the whatsapp share button. It is not working for mobile device. So for this reason we are unable to count number of sharing. But we check this into the desktop at this time analytics working properly.

Can you help me about this matter ?

We implemented our own solution for tracking the clicks:

html:

js:

$('a.counterBtn').unbind('click').bind('click', function(e){
e.preventDefault();
var href = this.href;
var ajaxlink = "counter.php"
$.post(ajaxlink, function(data, e){
window.location = href;
});

php:

and an empty clickcount.txt.

Simple solution for counting clicks.

Hope it helps.

Hi,

Already added this jquery into the html page.

jQuery(document).ready(function(){

          jQuery('.wa_btn').on('click', function() {
            ga('send', 'event', { eventCategory: 'whatsapptest', eventAction: 'share'});
            //alert('jquery');
         });


        });

But when we testing into the desktop at this time it is working, for mobile device we are unable to track

commented

@macsamiro This is not the solution you're looking for. It generates a request every time someone clicks the button. On high traffic websites this can lead to increased server load and/or crashes. Use an analytics software like GA or Piwik to track your clicks. If you want to count your clicks, you should use at least a database or your cms' core functions. Storing data in file like this is ... well, ugly.

@soumyajitcn I can't help you guys without a link to your setup/jsfiddle.

This is probably because the button is in an iframe and analytics is not loaded in that iframe. Therefore GA is not available.

Why is the button loaded in an iframe anyways :S

commented

Well, if you remove the iframe, the styling of the current page will be applyed to the button as well. On every second page the button looked awful because of some people thinking the css !important statement is the right way to go...

Hello,

After adding this jquery it is working properly.

jQuery(document).ready(function($){

          $('.wa_btn').unbind('click').bind('click', function(e){

            ga('send', 'event', { eventCategory: 'whatsapptest', eventAction: 'share'});

          });




        });

@kriskbx Thx for your reply. I understand you use an iframe to be able to offer it as a button generator. However I actually do want to apply my own styles (and a lot of others probably too), so I had to modify the plugin, which was kinda frustrating.

commented

@janniconl this library was not made to be heavily modified. It was made to enable people to integrate WA buttons on their websites as easy as possible. If you want your own styles, why messing around with libraries? It's just a useragent-check and an url-scheme. Feel free to fork the repo and build your own button upon it. :)

True, will probably do that! Thanks though

commented

The release v1.3.0 fixed some issues with onclick-handlers. This should be working now.