Repository navigation
Expand file tree
/
Copy pathexamples.html.md.erb
More file actions
61 lines (40 loc) · 2.01 KB
/
Copy pathexamples.html.md.erb
File metadata and controls
61 lines (40 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
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/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.