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

Randy ColeDigital Marketing, Marketing Director, Market Manager, IT DirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
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.
1
Randy ColeDigital Marketing, Marketing Director, Market Manager, IT DirectorAuthor Commented:
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?
0
Randy DownsOWNERCommented:
You can use the Tag Manager.0

Explicitly declaring a data layer is optional. Therefore, if you choose not to implement the data layer code and populate it with variables, the Google Tag Manager container snippet will initiate a data layer object for you.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.