1

I am having a products page in my site. In that I have a comparison functionality.

Now I want to send data to google analytics so that Admin can later on check which products were compared. I have captured the products I.E. on which products checkbox the user clicked and store that array of products in a jquery variable.

Now I want to send this variable in ga function but I am not able to do soo. Can anybody help me out with it or some other solution?

0

You can use GA Push module

GA Push offers an API to enqueue informations that are sent GA servers, and three submodules to track browser events (using jQuery), form validation errors and log exceptions.

So, you can use the API to send an event to Google Analytics when user adds a producto to the comparison.

For example, you can use the page view function and send virtual page views for each compared product:

$push = array(
  'location' => '/comparision/product/' . $nid,
  'page' => 'comparison',
  'title' => 'Product ' . $product_name . ' comparison',
);

ga_push_add_pageview($push);

This code should called when you detect that a product is being compared.

Disclaimer: I'm one of the developers of this module.

  • $(".page-personal-loans a.compare-btn").on('click', function(event){ var selected = []; $('.flag-compare-products input:checked').each(function() { var parent = $(this).parent().closest('td').text().replace(/remove/g,'').replace(/compare/g,'').trim(); selected.push(parent); }); $push = array( 'location' => '/comparision/product/' . $nid, 'page' => 'comparison', 'title' => 'Product ' . selected . ' comparison', ); ga_push_add_pageview($push); });.,i want to send values in selected variable to google analytics in one hit so we can calculate which product were compared – Rajat Maggo May 18 '16 at 6:13
  • If you are using Drupal 7 you can use GA Push Browser submodule to send data to GA at certain JS events. – sanzante May 18 '16 at 6:30
  • can we have skype call.I am having some issues over it – Rajat Maggo May 18 '16 at 6:45
  • No, in that way you are the only one that gets help. If we write here the questions and answers it may help other people. You may start a chat, though. – sanzante May 18 '16 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.