Solved: Tracking Virtual PageView via Google Tag Manager


What is the requirement of Virtual Page Views?

While working on a single page website(SPA) or any JavaScript based(ReactJS, AngularJS, BackBoneJS, etc) websites, the interactions of user actions are not straight forward and most of the content is rendered via JavaScript AJAX calls, without reloading the page.

Virtual Pageview: It’s not really a page view but are user actions which are tracked like the real page views. Some examples of them are:
– Infinite Scroll, Load more, Pagination.

– Lightbox, Modal box.

Events which are the core feature of Google Analytics allows tracking user interactions based on specific triggers.
Now, I’ll Show you how you can track the virtual pageviews with GTM(Google Tag Manager) V2:

1. Firstly, we need to setup Google Tag Manager and its container.

2. Setup GTM Data Layer Variables required:


Go to Variables -> User Defined Variables -> New

Setup variable named “virtualPageURL“:

Variable Page Url

Setup variable named “virtualPageTitle“:


Here the variables created for Virtual Pageview:


3. Setup GTM Virtual PageView Trigger:

Go to Triggers -> New

Choose Event as “Custom Event” and complete the required details:


4. On the website put the tracking javascript as per the requirement(load more, ajax infinite scroll, lightbox):

<script type="text/javascript">
      'virtualPageTitle':'News Page - 2'


5. Finally Setup the GTM Virtual PageView Tag:

Go to Tags -> New

– Create a Google Universal Analytics Tag.

– Insert Tracking ID

– Track Type: Page View

– Expand More settings, Fields to set:

Tags GTM

page : {{virtualPageUrl}}

title: {{virtualPageTitle}}

–  Select Firing Trigger to “Virtual Page View Trigger“.


Save and Publish.

Check Google Analytics Real-time Content Dashboard for the triggered page views now.

SyntaxError: Use of const in strict mode

I’m working with node.js, and in one of my js files I’m using const in "strict mode". When trying to run it, I’m getting an error:

SyntaxError: Use of const in strict mode.

If this is happening in nodejs, it is due to the older version of nodejs. Update node by using,

1) Clear NPM’s cache:

sudo npm cache clean -f

2) Install a little helper called ‘n’

sudo npm install -g n

3) Install latest stable NodeJS version

sudo n stable

Update nodejs instructions taken from,


Web performance Optimization

We optimize your website by analyzing the pattern of the website. By using improved methods of optimization we makes your web pages fly while rendering.

Some of the points from our checklist are:

  • By improving your code, optimizing JS for non-blocking while rendering.
  • Sharing the web page load(I/O) by using a CDN and Seprate Session and Caching servers.
  • By Using Caching technology like Varnish, aiCache.
  • Using shared network caching like Memcached, Redis.
  • Optimizing the structure of your website for faster rendering in browsers like IE.
  • Optimizing Database Servers like Mysql, PostgreSQL for dynamic websites.
  • Web Server Optimization for web servers like Nginx, Apache, IIS, Tomcat, IBM Http Server, JBOSS, Express.
  • Using right Headers for Cache Control.
  • Image Optimization and Compression.


Get list of product attribute in Magento

# Get list of colors from Magento Installation

Let’s create a file called getcolors.php on Magento root folder.

require_once ( “app/Mage.php” );
Mage::getSingleton(“core/session”, array(“name” => “frontend”));
$attribute = Mage::getSingleton(‘eav/config’)->getAttribute(‘catalog_product’, ‘color’);
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);

When you excute the file getcolors.php either from shell or browser, It will print the list of color used in product catalog.

Change a product’s attribute value without loading the entire product model

Loading product in a collection and saving them again and again over will take lot of time. To make it quick there is an alternate solution available which uses the same function used by Update attributes action from the product grid:

->updateAttributes(array($productId), array('attribute_code'=>'value'), 0);

Parse query string in shell script

Sometimes we have to integrate multiple languages like node.js/php/shell script into bash shell script and parse query string to array for supplying query string data for manipulation.

Here is the simple script which will help you to achieve that goal:

#!/usr/bin/env bash
declare -A querydict
populate_querystring_array () {
while IFS== read arg value
done < <(echo “$query” | sed ‘s/&/\n/g’ )

populate_querystring_array “$q”
printf “${querydict[user]}\n”

No package ‘opencv’ found

If you are getting this error while compiling certain modules which requires opencv library which is causing the execution to be aborted.

For fixing it, you need to install lib-opencv using following command:

Ubunntu/Debian – sudo apt-get install libopencv-dev

Centos/Red Hat – sudo yum install opencv-devel

After you do so, pkg-config –cflags opencv and pkg-config –libs opencv will work as expected.

Using underscore.js with node.js


Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery‘s tux andBackbone‘s suspenders.

Underscore provides over 100 functions that support both your favorite workaday functional helpers: mapfilterinvoke — as well as more specialized goodies: function binding, javascript templating, creating quick indexes, deep equality testing, and so on.


To install underscore.js in a node.js project use: npm install underscore

After installing it you can use underscore now on your node.js project as : var _ = require(‘underscore’);

Things you can do with _ :

1. Merge two json objects:

var obj1 = {foo:”bar”};

var obj2 = {name:”john”};

var merged = _.extend(obj1,obj2);



Error: /lib64/ version ‘GLIBC_2.14’ not found

Sometimes on your node.js project you have seen problems like “Error: /lib64/ version ‘GLIBC_2.14’ not found” by some npm modules.

Error: /lib64/ version ‘GLIBC_2.14’ not found

This error comes when the available version of glibc is not compatible by the node module.

So, if you still want to work with that module, you need to rebuild that module on your project.

To do this simply go to Github, Clone a repo for node module where its installed in project, may be in node_modules directory.

Inside the node_modules directory clone that repo:

Example- git clone

Now go to the cloned module, cd node-expat

Then install all node module dependencies.
npm install

After installing it to a clean build for that module:
node-gyp rebuild

Voila! Use the module in your project now.

Better way to load layout blocks outside of Magento

For loading Magento Layout Blocks externally or in a controller without any complexity, use this:

From external file, we need to initiate Magento session:

Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$session = Mage::getSingleton(‘customer/session’, array(‘name’=>’frontend’));
$layout = Mage::app()->getLayout();
$top = $layout->getBlock(‘top.links’)->toHtml();
echo $top;

From internal controller:

$layout = Mage::app()->getLayout();
$top = $layout->getBlock(‘top.links’)->toHtml();
echo $top;

How to configure libstdc++ with GCC 4.8?

You need to tell your dynamic linker (it’s executed when you run your program) where to find the library. Set LD_LIBRARY_PATH to the path of the library (probably somewhere under /app/gcc/4.8.0/lib or something).

Use find /app/gcc/4.8.0 -name “”. Add the directory to your LD_LIBRARY_PATH. e.g with the path I mentioned:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/gcc/4.8.0/lib (if you’re using a bourne-like shell which the default on Linux).

Then try to run your program.


Openresty : Programming with Magento/Mysql – Get Inventory of Products REST API

Skills Requried – LUA, nginx, mysql

If you have nginx-openresty installed, open the vhost file of your domain, than follow this:

Let your REST API path is http://<your-domain>.com/getstockserv?p=123450,12145

where p is the parameter where all product ids of Magento Products has been supplied.

Now add this entry to the vhost file –

location ^~ /getstockserv {
content_by_lua ‘
local mysql = require “resty/mysql”;
local cjson = require “cjson”;
args = ngx.req.get_uri_args();
local query = “select product_id from cataloginventory_stock_item where is_in_stock = 0 and product_id in (“.. args.p ..”)”;
local db, err = mysql:new();

local ok, err, errno, sqlstate = db:connect{
host = “<Enter Mysql Hostname>”,
port = 3306,
database = “<Enter Database Name>”,
user = “<Enter Mysql User>”,
password = “<Enter Mysql Password>”,
max_packet_size = 1024 * 1024 };
res, err, errno, sqlstate = db:query(query);
ngx.header[“Content-Type”] = “application/json”;

Reload nginx : nginx -s reload

Voila!! Now you can get the inventory of products without using Magento.

How to add a Volume to EC2 Instance?

Go to EC2 console to create the volume and attach it to the instance, and then we’ll mount the volume to make it available.

– under Elastic Block Store, click Volumes.
– Click on Create Volume – Select the General Purpose (SSD) volume type.
– Wait for your Volume to be available.
– Right click on it and select Attach Volume, Select the instance and specify an unused device name say /dev/xvdk

For making it available follow these steps:

[ec2-user ~]$ lsblk
xvdk    202:80   0   22G  0 disk
xvda1   202:1    0    8G  0 disk /

here xvdk device is not mounted.

To Mount it – mkfs -t ext4 /dev/xvdk
# mkdir /mnt/space
# mount /dev/xvdf /mnt/space

Voila, You just added the volume to the system.

To check it, df -h

[ec2-user ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.1G  6.8G  14% /
tmpfs                 298M     0  298M   0% /dev/shm
/dev/xvdk              22G     0   22G   0% /mnt/space

How to make nginx works with Geo IP?

NGINX GeoIP Installation:

Follow these steps to install GeoIP with nginx:


tar -zxvf GeoIP.tar.gz
cd GeoIP-1.4.8/
make install
echo ‘/usr/local/lib’ > /etc/
yum install gcc pcre-devel.x86_64 openssl-devel.x86_64
yum install readline-devel pcre-devel openssl-develWe are using openresty – nginx here:wget
tar xzvf ngx_openresty-
cd ngx_openresty-
./configure –with-luajit –with-http_geoip_module
gmake installwget -O /usr/local/share/GeoIP/GeoIP.dat.gz
gunzip /usr/local/share/GeoIP/GeoIP.dat.gz
In nginx.conf  http block – geoip_country /usr/local/share/GeoIP/GeoIP.dat;Reload nginx – nginx -s reload

Nginx Openresty Get/Set Cookies using LUA.

To set cookies using lua while using nginx_lua module in openresty/nginx server, use this code:

local expires = 3600 * 24  — 1 day
ngx.header[“Set-Cookie”] = “session=demo; Path=/; Expires=” .. ngx.cookie_time(ngx.time() + expires)

This will set cookie session = demo for 1 day from current time on path /.

Use PHP Functions in LUA Code

Based on [PHP explode]
Example: explode(” and “,”one and two and three and four”) –> {“one”,”two”,”three”,”four”}
Compatibility: Lua 5.0 and 5.1function explode(div,str)
if (div==”) then return false end
local pos,arr = 0,{}
— for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) — Attach chars left of current divider
pos = sp + 1 — Jump past current divider
table.insert(arr,string.sub(str,pos)) — Attach chars right of last divider
return arr
Based on [PHP implode]Use table.concat:

PHP implode(join,array) is equivalent to Lua table.concat(table,join)

PHP: implode(” “,array(“this”,”is”,”a”,”test”,”array”)) –> “this is a test array”

Lua: table.concat({“this”,”is”,”a”,”test”,”array”},” “) –> “this is a test array”

Reference –