Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
refs #41
Browse files Browse the repository at this point in the history
 * Additional code changes for having correct interface and implementations
 * including README changes
  • Loading branch information
Robert Kummer committed Feb 22, 2017
1 parent 7831a5c commit b309200
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 89 deletions.
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,20 @@ Add ecommerce transaction to tracking code.
/**
* ecommerce tracking - add transaction
*
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null);
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null);

Available since 1.2.2.
Available since 1.2.2. Parameter `$currency` since 1.3.3.

Since version 1.3.3 the [multi currency](https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multicurrency) tracking is supported with currency values defined [here](https://support.google.com/analytics/answer/6205902#supported-currencies).

### Analytics::ecommerceAddItem()

Expand All @@ -489,18 +492,21 @@ Add ecommerce item to tracking code.
/**
* ecommerce tracking - add item
*
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null);
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null);

Available since 1.2.2.
Available since 1.2.2. Parameter `$currency` since 1.3.3.

Since version 1.3.3 the [multi currency](https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#multicurrency) tracking is supported with currency values defined [here](https://support.google.com/analytics/answer/6205902#supported-currencies).

### Analytics::setCustom()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,31 @@ public function disableEcommerceTracking();
/**
* ecommerce tracking - add transaction
*
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null);
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null);

/**
* ecommerce tracking - add item
*
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null);
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null);

/**
* sets custom dimensions
Expand Down
113 changes: 65 additions & 48 deletions src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,23 @@ public function trackEvent($category, $action, $label = null, $value = null)
/**
* ecommerce tracking - add transaction
*
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null)
public function ecommerceAddTransaction(
$id,
$affiliation = null,
$revenue = null,
$shipping = null,
$tax = null,
$currency = null
)
{
// Call to enable ecommerce tracking automatically
$this->enableEcommerceTracking();
Expand All @@ -238,7 +246,7 @@ public function ecommerceAddTransaction($id, $affiliation = null, $revenue = nul
if (!is_null($currency)) {
$parameters['currency'] = $currency;
}

$jsonParameters = json_encode($parameters);
$trackingCode = "ga('ecommerce:addTransaction', {$jsonParameters});";

Expand All @@ -250,23 +258,32 @@ public function ecommerceAddTransaction($id, $affiliation = null, $revenue = nul
/**
* ecommerce tracking - add item
*
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null)
public function ecommerceAddItem(
$id,
$name,
$sku = null,
$category = null,
$price = null,
$quantity = null,
$currency = null
)
{
// Call to enable ecommerce tracking automatically
$this->enableEcommerceTracking();

$parameters = [
'id' => $id,
'name' => $name,
'id' => $id,
'name' => $name,
];

if (!is_null($sku)) {
Expand Down Expand Up @@ -596,7 +613,7 @@ public function setUserId($userId)
}

/**
* unsets a possible given user id
* unset a possible given user id
*
* @return AnalyticsProviderInterface
*/
Expand Down Expand Up @@ -640,7 +657,7 @@ public function setCampaign(Campaign $campaign)
}

/**
* unsets a possible given campaign
* unset a possible given campaign
*
* @return AnalyticsProviderInterface
*/
Expand All @@ -651,36 +668,6 @@ public function unsetCampaign()
return $this;
}

/**
* returns start block
*
* @return string
*/
protected function _getJavascriptTemplateBlockBegin()
{
$appendix = $this->debug ? '_debug' : '';

$scriptTag = ($this->cspNonce === null)
? '<script>'
: '<script nonce="' . $this->cspNonce . '">';

return ($this->renderScriptBlock)
? $scriptTag . "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics{$appendix}.js','ga');"
: '';
}

/**
* returns end block
*
* @return string
*/
protected function _getJavascriptTemplateBlockEnd()
{
return ($this->renderScriptBlock)
? '</script>'
: '';
}

/**
* enables Content Security Polity and sets nonce
*
Expand Down Expand Up @@ -716,4 +703,34 @@ public function cspNonce()
{
return $this->cspNonce;
}

/**
* returns start block
*
* @return string
*/
protected function _getJavascriptTemplateBlockBegin()
{
$appendix = $this->debug ? '_debug' : '';

$scriptTag = ($this->cspNonce === null)
? '<script>'
: '<script nonce="' . $this->cspNonce . '">';

return ($this->renderScriptBlock)
? $scriptTag . "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics{$appendix}.js','ga');"
: '';
}

/**
* returns end block
*
* @return string
*/
protected function _getJavascriptTemplateBlockEnd()
{
return ($this->renderScriptBlock)
? '</script>'
: '';
}
}
28 changes: 15 additions & 13 deletions src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,32 +245,34 @@ public function disableEcommerceTracking()
/**
* ecommerce tracking - add transaction
*
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param string $id
* @param null|string $affiliation
* @param null|float $revenue
* @param null|float $shipping
* @param null|float $tax
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null)
public function ecommerceAddTransaction($id, $affiliation = null, $revenue = null, $shipping = null, $tax = null, $currency = null)
{
return $this;
}

/**
* ecommerce tracking - add item
*
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param string $id
* @param string $name
* @param null|string $sku
* @param null|string $category
* @param null|float $price
* @param null|int $quantity
* @param null|string $currency
*
* @return AnalyticsProviderInterface
*/
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null)
public function ecommerceAddItem($id, $name, $sku = null, $category = null, $price = null, $quantity = null, $currency = null)
{
return $this;
}
Expand Down

0 comments on commit b309200

Please sign in to comment.