0

There are many QR codes that contains URL of website such as:(it just demos link)

http://www.popupstore.com/index.php?qrcode_type=magazine&location=Singapore http://www.popupstore.com/index.php?qrcode_type=banner&location=Vietnam

I need a way can summary to know that where customer come from (nearly same as source/channel in Google Analytics):

  • Type: Mazazine, banner, etc.
  • Location: Vietnam, Singapore, etc.

Can anyone help me please :)

HungDQ
  • 315
  • 1
  • 5
  • 15

1 Answers1

1

You could create two Custom Dimensions, each for Type and another for Country

As per your need define the appropriate Scope of the dimension, a Hit level or Session level scope would be appropriate.

You need to push custom dimensions into Google Analytics i.e. additonal JS code in your site.

ga('send', 'pageview', {
  'dimension1':  'Magzine',
   'dimension2':  'Singapore'
});

How this works

  • User scans the code and visits the store
  • Site has a JS code snippet that would get the query parameters from the URL and sets a custom dimension for each parameter
  • Setting the custom dimension would let Google Analytics know the value of the Type and Country

It is your JS code that tells Google Analytics what value to take for custom dimension. Google Analytics would not know that the value came from the URL.

To get a query parameter value via javascript you can refer to this answer, If you take the function provided there by Jan Turon (head over and give him an upvote of this helps you):

function getJsonFromUrl() {
  var query = location.search.substr(1);
  var result = {};
  query.split("&").forEach(function(part) {
    var item = part.split("=");
    result[item[0]] = decodeURIComponent(item[1]);
  });
  return result;
}

You can use this to dynamically set the dimensions based on the url. You first call the function to return an JSON object that has the key/value pairs from the query parameters, then you insert the needed values to set the dimensions:

 result = getJsonFromUrl();
 ga('send', 'pageview', {
      'dimension1':  result.qrcode_type,
      'dimension2':  result.location
    });
Community
  • 1
  • 1
Sudhir Mishra
  • 578
  • 2
  • 16
  • I tried to add custom dimension but I don't know how Google Analytics can understand my dimension appropriate with URL parameters ? – HungDQ Jun 30 '15 at 09:51
  • It is your JS code that tells Google Analytics what value to take for custom dimension. Google Analytics would not know that the value came from the URL. – Sudhir Mishra Jun 30 '15 at 11:15
  • @SudhirMishra, I took the liberty of editing your answer to include a way of reading the query parameters by javascript. Also I don't think it's a good idea to do a pageview call for each dimension (since this would double the number of pageviews) so I changed that a bit, too. – Eike Pierstorff Jul 01 '15 at 10:02