public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null)
{
// Call to enable ecommerce tracking automatically
$this->enableEcommerceTracking();
$parameters = ['id' => $id];
if (!is_null($affiliation)) {
$parameters['affiliation'] = $affiliation;
}
if (!is_null($revenue)) {
$parameters['revenue'] = $revenue;
}
if (!is_null($shipping)) {
$parameters['shipping'] = $shipping;
}
if (!is_null($tax)) {
$parameters['tax'] = $tax;
}
$jsonParameters = json_encode($parameters);
$trackingCode = "ga('ecommerce:addTransaction', {$jsonParameters});";
$this->trackingBag->add($trackingCode);
return $this;
}