Permalink
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (40 sloc) 2.02 KB
---
parent: analytics
title: examples
---
# Examples <%= edit_link %>
The document demonstrates working example implementations to successfully track
your sales. Typically, an implementation consists of the following steps:
1. Prepare the Ecommerce data (order, items) on the server
2. Load the Analytics.js library
3. Report the Ecommerce data
<%= partial 'partials/toc' %>
## Prepare Ecommerce data
The first step is to prepare the Ecommerce data of a completed order.
Analytics reports data using the user's browser. Thus, some server-side logic
is required to dynamically provide the ecommerce data to the browser for
the Analytics client to report them.
##### Server-side Ecommerce data structure
Typically, the Ecommerce data on the server-side could have the following
structure:
<%= render_code_from_file 'analytics/examples/php/order_declaration' %>
##### JavaScript representation of Ecommerce data
Example server-side snippets to transform Ecommerce data on the server for into
JavaScript strings for Analytics could look like:
<%= render_code_from_file 'analytics/examples/php/order_preprocessing' %>
## Load Analytics.js
Next, add the Analytics.js tracking code to enable Analytics on your website.
You may add it just before closing either the `<head>` or `<body>` section.
<%= render_code_from_file "analytics/#{flavor}/js_snippet" %>
> ##### Note
> You **have to** replace the `'SA-XXXX-YYYY'` property with the actual *Shop Account ID*
you received from us.
> For your shop to report all required data to Analytics you **must** proceed to
the <%= link_to 'next step', '/analytics/examples', anchor: 'report-ecommerce-data' %>.
## Report Ecommerce data
Finally, additional server-side logic is required to dynamically output the
transformed Ecommerce data. Before the closing tag of the `</body>` add the
following snippet, for the declaration of Analytics actions to happen:
<%= render_code_from_file 'analytics/examples/php/order_rendering' %>
> ##### Note
> Be sure to report any data **after** the Analytics.js declaration.