Ipunkt\LaravelAnalytics\Providers\GoogleAnalytics::ecommerceAddTransaction PHP Method

ecommerceAddTransaction() public method

ecommerce tracking - add transaction
public ecommerceAddTransaction ( string $id, null | string $affiliation = null, null | float $revenue = null, null | float $shipping = null, null | float $tax = null ) : Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface
$id string
$affiliation null | string
$revenue null | float
$shipping null | float
$tax null | float
return Ipunkt\LaravelAnalytics\Contracts\AnalyticsProviderInterface
    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;
    }