We have setup Google Analytics Ecommerce Tracking through Google Tag Manager.


$tracking_script = "
    'transactionId': '$ref',
    'transactionAffiliation': '$cartec_name',
    'transactionTotal': '$amount',
    'transactionTax': '',
    'transactionShipping': '',
    'transactionProducts': [{
        'sku': 'DD-{$amount}-{$currency}',
        'name': '{$cartec_name}_Deposit',
        'category': '',
        'price': '$amount',
        'quantity': 1
    'event': 'deposit_successful'
<script type="text/javascript">
    if (typeof(dataLayer) !== 'undefined') {
        <?php echo $tracking_script; ?>

Tracking works but we have about 200 (30%) transactions missing per day compared to our database records.

What are the possible causes and what are the best methods for debugging this problem?

  • What percentage is 200 transactions? If its half of your transactions, you likely have an implementation bug. If it is 10%, that would likely be users with blocking software. May 26, 2015 at 13:58
  • There are about 30% missing
    – Taner
    May 26, 2015 at 14:43
  • Are you using Google Tag Assistant in your browser? Just follow your pushes to the dataLayer in every step of the process. Also try to find correlation between discrepancies and "possible path" taken by the visitors.
    – lucgenti
    May 26, 2015 at 18:52
  • I used measurement protocol API in the same page alongside the GTM code to send the data from server-side, and there is a difference of: 611 / 567 (measurement protocol / GTM+analytics.js) for one product in one day. Looks like there is a problem with JS, or many users are using blocking software but 30% seems a bit too much.
    – Taner
    Jun 1, 2015 at 8:33

2 Answers 2


Your script is running before the GTM's dataLayer object is ready as it's retrieved asynchronously. This means you need to wait the load event is fired/triggered.

Your server side php code is not good as is writing into the dataLayer and definitely is the root issue this code is not awaiting for the GTM's datalayer object. Instead of this just create a variable to be ready for js.

 $tracking_script = "var myObject = {your object code}";

Before the push code you need to put somewhere the php code to create the var

<script type="text/javascript">
  <?php echo $tracking_script; ?>

Then you can use the load event to properly inject the server side code into the GTM's dataLayer. You can use the next gist:


Then just add your lines inside the callback function:

var callBack = function(){
     var myObject = myObject || {};
     dataLayer = dataLayer || [];

Or use jQuery like

 $( window ).load(function() {
      // Run code
         var myObject = myObject || {};
         dataLayer = dataLayer || [];
  • Is it the same thing if I set the trigger type of the Universal Analytics tag to DOM Ready or Window Loaded instead of Custom Event?
    – Taner
    Jun 19, 2015 at 8:59
  • Depends what's the custom event and ready is not equal to load event
    – mario ruiz
    Jun 19, 2015 at 15:00
  • Sorry, I forgot to add that part of the code, just updated the code in my question. So the event would be something like dataLayer.push({'event': 'deposit_successful'}); and I would set that up as the triggering event for that tag in google tag manager.
    – Taner
    Jun 19, 2015 at 16:43

A 30% discrepancy between Google Analytics and your database is normal as many users use ad blockers which is preventing the script from Google Analytics to load thus to track anything.

  • In addition to ad blockers, there is the "do not track" browser/app settings, and also specific script blockers such as Chromes "Disconnect" extension. These types of settings/extensions do not trigger the "ad blocker detected" mechanisms, so may be harder to fingerprint as a cause at the user level.
    – dhaupin
    Jun 1, 2019 at 21:54
  • @dhaupin can you please give more details about "ad blocker detected" mechanisms which you were referring to? Are you referring to track in GA if client has ad blocker or not? Jun 2, 2019 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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