# Capturing existing classic GA calls with GTM – Solutions Corner #4

> Learn how to migrate classic GA calls using GTM, capture legacy gaq pushes before GTM loads and preserve your analytics data.

Source: https://www.measurelab.co.uk/insights/blog/gtm-solutions-corner-4-capturing-existing-classic-ga-calls/  
Author: Adam Englebright  
Published: 2020-01-29  
Updated: 2026-01-27

This is part 4 of [a semi-regular series](https://www.measurelab.co.uk/insights/tag/gtm-solutions-corner/), dedicated to reusable GTM solutions for scenarios or issues we’ve encountered more than once.

### The challenge with pre-GTM classic calls

Last time, we looked at [how to turn on-page classic Google Analytics calls to data layer pushes](https://www.measurelab.co.uk/insights/gtm-solutions-corner-3-turning-classic-ga-calls-into-data-layer-pushes/), and this time we'll be looking at a supplement to that—what if the classic GA call you're looking to capture is *before* GTM loads? This pretty much only matters for ecommerce, so that's what the solution focuses on.

We start by defining some variables:

```
var gaq = window._gaq;
var ctdl_obj = {};
var ctdl_arr = [];
```

The second two are where we're going to push some values a bit later, and the first one is getting the existing _gaq object.

```
for(i=0;i < gaq.length;i++){
```

Now we're going to start looping through gaq to see what's in there.

```
 if(gaq[i][0] === "_addTrans"){
    window.ctdl_obj.id = gaq[i][1];
    window.ctdl_obj.affiliation = gaq[i][2];
    window.ctdl_obj.revenue = gaq[i][3];
```

If we find a "_addTrans" which is the push that adds the transaction-level information, we write it into the *ctdl_obj* we created at the beginning, in Enhanced Ecommerce format.

```
 } else if(gaq[i][0] === "_addItem"){
    window.ctdl_arr.push({
          'id':gaq[i][2],
          'name':gaq[i][3],
          'category':gaq[i][4],
		      'price':gaq[i][5],
          'quantity':gaq[i][6]
        })
```

Then if it's "_addItem", the pushes which add items (obviously!) we push that into the *ctdl_arr*array we created earlier.

```
 } else if(gaq[i][0] === "_trackTrans"){
    dataLayer.push({
          'event': 'hcga_trans',
            'ecommerce': {
        		'purchase':{
          			'actionField' : window.ctdl_obj,
          			'products' : window.ctdl_arr
        					}
      					}
        			}
				);
  }
}
```

Finally, once we hit the "_trackTrans" push, we arrange all the stuff we've gathered into EE format and push it into the data layer.

### Next steps

Once you’ve added this in a custom HTML tag to fire where it's needed, you’ll need to configure a GA tag to fire on the data layer push. [The solution is also available in full on the Measurelab Github](https://github.com/Measurelab/measurelab_gtm_solutions/blob/master/classic-to-dl/alt_gaq_grabber). Please [drop me a line](mailto:adam@measurelab.co.uk) if you’ve got any questions or ideas for improvement!
