Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
integration:googleanalytics_universal [2014/03/18 13:44] – [Setting Up Google Analytics] adam | integration:googleanalytics_universal [2021/09/10 09:31] (current) – [Setting Up Your Site] adam | ||
---|---|---|---|
Line 17: | Line 17: | ||
<WRAP center round important 80%> | <WRAP center round important 80%> | ||
These instructions are new, and while we have done some testing on the set up - the following are new instructions. Where possible we recommend testing this set up on a test profile before setting to your live analytics account, to ensure it works perfectly for your store. Any questions or issues, please get in touch with us. | These instructions are new, and while we have done some testing on the set up - the following are new instructions. Where possible we recommend testing this set up on a test profile before setting to your live analytics account, to ensure it works perfectly for your store. Any questions or issues, please get in touch with us. | ||
+ | </ | ||
+ | |||
+ | <WRAP center round info 80%> | ||
+ | **Using FoxyCart 2.0?** Google Analytics is now a configuration option within your store' | ||
</ | </ | ||
Line 57: | Line 61: | ||
- Under ' | - Under ' | ||
- Click 'Add Referral Exclusion' | - Click 'Add Referral Exclusion' | ||
+ | - If your own website domain isn't present in that list - add it as well. | ||
- Proceed to the next section | - Proceed to the next section | ||
Line 128: | Line 133: | ||
Proceed to the next section. | Proceed to the next section. | ||
===== Setting Up Your Site ===== | ===== Setting Up Your Site ===== | ||
- | - On your own site, add the following to each page (except your FoxyCart cart, checkout and receipt templates), right before the closing ''</ | + | - On your own site, add the following to each page (except your FoxyCart cart, checkout and receipt templates), right before the closing ''</ |
(function(i, | (function(i, | ||
(i[r].q=i[r].q||[]).push(arguments)}, | (i[r].q=i[r].q||[]).push(arguments)}, | ||
Line 139: | Line 144: | ||
</ | </ | ||
<script type=" | <script type=" | ||
- | | + | |
- | if (arr[' | + | if (arr[' |
- | return true; | + | return true; |
- | } | + | } |
- | if (arr[' | + | if (arr[' |
- | ga(' | + | if (window.ga && ga.loaded) { |
- | ' | + | |
- | jQuery.getJSON(' | + | ' |
- | fcc.events.cart.preprocess.resume(); | + | jQuery.getJSON(' |
- | }); | + | fcc.events.cart.preprocess.resume(); |
+ | }); | ||
+ | } | ||
+ | }); | ||
+ | return " | ||
+ | } else { | ||
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | return true; | ||
+ | }); | ||
+ | //CAUSING LOOPING ISSUES IN CHROME | ||
+ | fcc.events.cart.process.add_pre(function (e, arr) { | ||
+ | if (window.ga && ga.loaded) { | ||
+ | ga(function (tracker) { | ||
+ | jQuery.getJSON(' | ||
+ | fcc.events.cart.process.resume(); | ||
+ | }); | ||
+ | }); | ||
+ | return " | ||
+ | } else { | ||
+ | return true; | ||
} | } | ||
- | }); | ||
- | return " | ||
- | } | ||
- | return true; | ||
- | }); | ||
- | fcc.events.cart.process.add_pre(function(e, | ||
- | ga(function(tracker) { | ||
- | jQuery.getJSON(' | ||
- | fcc.events.cart.process.resume(); | ||
- | }); | ||
}); | }); | ||
- | return " | ||
- | }); | ||
</ | </ | ||
+ | |||
+ | * <wrap hi>The above script includes the Google Analytics tracking code.</ | ||
* <wrap info>In case you're wondering...</ | * <wrap info>In case you're wondering...</ | ||
- Do not put this code in your cart, checkout, or receipt templates. | - Do not put this code in your cart, checkout, or receipt templates. | ||
Line 169: | Line 185: | ||
===== Setting Up Your FoxyCart Templates, The Full Details ===== | ===== Setting Up Your FoxyCart Templates, The Full Details ===== | ||
- | Copy the following and paste it above the closing ''</ | + | Copy the following and paste it above the closing ''</ |
=== The Cart Template === | === The Cart Template === | ||
Line 192: | Line 208: | ||
} | } | ||
$(' | $(' | ||
- | e.preventDefault(); | + | |
- | var link_url = jQuery(this).attr(" | + | |
- | var gateway = (jQuery(this).hasClass(" | + | var link_url = jQuery(this).attr(" |
- | ga(' | + | var gateway = (jQuery(this).hasClass(" |
- | ' | + | ga(' |
- | $form = jQuery('< | + | ' |
- | jQuery.getJSON(' | + | $form = jQuery('< |
- | $form.submit(); | + | jQuery.getJSON(' |
- | }); | + | $form.submit(); |
- | } | + | }); |
- | }); | + | } |
+ | }); | ||
+ | } | ||
}); | }); | ||
}); | }); | ||
Line 223: | Line 241: | ||
</ | </ | ||
<script type=" | <script type=" | ||
+ | var originalValidateAndSubmit = FC.checkout.validateAndSubmit; | ||
function ga_tracker() { | function ga_tracker() { | ||
+ | var wait = false; | ||
if (typeof(fc_json.custom_fields[' | if (typeof(fc_json.custom_fields[' | ||
var method, method_co, source = ""; | var method, method_co, source = ""; | ||
- | |||
if (typeof(fc_json.custom_fields[' | if (typeof(fc_json.custom_fields[' | ||
var fcpm = fc_json.custom_fields[' | var fcpm = fc_json.custom_fields[' | ||
Line 232: | Line 251: | ||
source = fcpm[1]; | source = fcpm[1]; | ||
} | } | ||
- | |||
if (jQuery(" | if (jQuery(" | ||
method_co = jQuery(" | method_co = jQuery(" | ||
Line 238: | Line 256: | ||
method_co = jQuery(" | method_co = jQuery(" | ||
} | } | ||
- | |||
if (method != method_co || source == " | if (method != method_co || source == " | ||
method = method_co; | method = method_co; | ||
source = " | source = " | ||
- | jQuery.getJSON(' | + | |
- | if (method != " | + | |
- | ga(' | + | fc_json = cart; |
- | } | + | if (method != " |
- | } | + | ga(' |
+ | } | ||
+ | originalValidateAndSubmit(); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (!wait) { | ||
+ | originalValidateAndSubmit(); | ||
} | } | ||
} | } | ||
- | FC.checkout.overload(' | + | FC.checkout.override(' |
</ | </ | ||
=== The Receipt Template === | === The Receipt Template === | ||
- | There are three lines of Twig code that you need to alter in the receipt template - depending on the specific locale that your store is set to. See below the following code block on how to adjust these. | ||
<code javascript>< | <code javascript>< | ||
(function(i, | (function(i, | ||
Line 277: | Line 301: | ||
{% endif %} | {% endif %} | ||
</ | </ | ||
- | < | + | {% if first_receipt_display %} |
- | | + | |
- | {# Update these three variables based on your store configuration #} | + | {% endif %}</ |
- | {% set c_symbol = " | + | |
- | {% set c_thousands = "," | + | |
- | {% set c_decimal = " | + | |
- | + | ||
- | {% set ga_order_total = order_total|replace({ (c_symbol):"", | + | |
- | {% set ga_shipping_total = receipt_shipping_cost|replace({ (c_symbol):"", | + | |
- | {% set ga_tax_total = receipt_tax|replace({ (c_symbol):"", | + | |
- | {% if c_decimal != " | + | |
- | {% set ga_order_total = ga_order_total|replace({ (c_decimal):" | + | |
- | {% set ga_shipping_total = ga_shipping_total|replace({ (c_decimal):" | + | |
- | {% set ga_tax_total = ga_tax_total|replace({ (c_decimal):" | + | |
- | | + | |
- | ga(' | + | |
- | ga(' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | }); | + | |
- | {% for item in items %} | + | |
- | {% set ga_price_each = item.price_each|replace({ (c_symbol):"", | + | |
- | {% if c_decimal != " | + | |
- | {% set ga_price_each = ga_price_each|replace({ (c_decimal):" | + | |
- | {% endif %} | + | |
- | ga(' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | }); | + | |
- | {% endfor %} | + | |
- | ga(' | + | |
- | {% endif %} | + | |
- | </ | + | |
- | + | ||
- | The three lines you may need to alter for the receipt template are: | + | |
- | <code javascript> | + | |
- | {% set c_thousands = "," | + | |
- | {% set c_decimal = " | + | |
- | + | ||
- | If your store uses Euro' | + | |
- | <code javascript> | + | |
- | {% set c_thousands = " | + | |
- | {% set c_decimal = "," | + | |
===== Testing ===== | ===== Testing ===== | ||
- | {{ http://img.skitch.com/ | + | {{ https://skitch-img.s3.amazonaws.com/ |
First off, <wrap tip>we strongly recommend creating a new profile in Google Analytics to test with.</ | First off, <wrap tip>we strongly recommend creating a new profile in Google Analytics to test with.</ | ||