Link to home
Start Free TrialLog in
Avatar of Randy Cole
Randy ColeFlag for United States of America

asked on

Google Analytics Data Layer - is this code the only code I need to install on my site (other than my UA tracking code)

I'm trying to capture some data from an e-commerce session. The product name, price, etc will be ever-changing and the quantity, transaction ID and total amount will obviously differ for each purchase. My question, is the code below the ONLY code I need to install to use the data layer in conjunction with Google Analytics? The support on Google's site is difficult for me to understand, at first they say this is the code to install and then their next example shows the code with transaction ID, price, etc.  I'm assuming that information is passed into the data layer as an array provided the code pasted below is installed exactly as I pasted it.

<script>
  dataLayer = [];
</script>
<script>
  dataLayer = [];
</script>

Open in new window

Avatar of Randy Downs
Randy Downs
Flag of United States of America image

That's an empty data layer so won't accomplish anything.

<script>
  dataLayer = [];
</script>

Open in new window


The above snippet is an empty object that can be populated with information to pass to Google Tag Manager.

if you choose not to implement the data layer, you can still access values from the page using the the Macros feature, but you cannot use events without the data layer. Implementing the data layer with variables and associated values, as opposed to waiting for those variables to load throughout the page, ensures that they will be available as soon as you need them to fire tags.
Avatar of Randy Cole

ASKER

Thanks Randy: if I want to pass data such as price and quantity into the data layer, will I need to hard code that into the data layer snippet or is it something that I can populate with Google Tag Manager?
ASKER CERTIFIED SOLUTION
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial