Vlad Preda
Vlad Preda

Reputation: 9920

Correctly add dataLayer information (dataLayer vs ga('ec:...')

I want to implement Google dataLayer for a client, and after reading docs, articles, and trying out browser extensions, I am still a bit confused.

I saw 2 versions of it being used:

dataLayer.push('ecommerce': {
    'detail': {/* data */},
    'impressions': [{/* data */}]     
});

and

ga('ec:addImpression', {'id':'%s', 'name':'%s',  'category':'%s', 'brand':'%s', 'position':%s, list: '%s'}) 
ga('send', 'pageview');

Is there a preferred version, or do both work ? Also, for the second option, do I need to use ga('send', 'event', '......') each time after using the ga('ec:something') function ?

Upvotes: 0

Views: 153

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32780

First one is the dataLayer as used in Google Tag Manager.

The second is not a dataLayer at all, these are direct calls to the Google Analytics tracking code (which would need to be loaded for this to work).

So these are two different things, if you really intend to implement a dataLayer to use with a tag management solution you need the first solution.

And not to be unkind, but if you can't tell the difference you should start by reading Google's really extensive documentation. From your question it is not even clear what you intend to do, since dataLayer is not a Google product, it's just a variable that feeds into Google's tag management solution.

Upvotes: 1

Related Questions