You are here

function _ga_push_method_analytics_js_push_ecommerce_script in GA Push 8

Same name and namespace in other branches
  1. 7 inc/ga_push.analytics_js.inc \_ga_push_method_analytics_js_push_ecommerce_script()

Generates the ga JS code for pushing an ecommerce to GA.

Parameters

array $push: Event data.

Return value

string JS code with push code.

1 call to _ga_push_method_analytics_js_push_ecommerce_script()
ga_push_method_analytics_js_push_script in inc/ga_push.analytics_js.inc
Generate the GA Push script code by type.

File

inc/ga_push.analytics_js.inc, line 122
Universal Analytics js: method and functions.

Code

function _ga_push_method_analytics_js_push_ecommerce_script(array $push) {

  // Include needed additional ga e-commerce library.
  $script = "ga('require', 'ecommerce', 'ecommerce.js');\n";

  // Transaction:
  $script .= "ga('ecommerce:addTransaction', " . json_encode($push['trans']) . ");\n";

  // Items:
  foreach ($push['items'] as $value) {
    $script .= "ga('ecommerce:addItem', " . json_encode($value) . ");\n";
  }

  // Sending!
  $script .= "ga('ecommerce:send');\n";
  return $script;
}