PHP code example of marshmallow / google-analytics
1. Go to this page and download the library: Download marshmallow/google-analytics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marshmallow / google-analytics example snippets
namespace App\Events;
use Marshmallow\GoogleAnalytics\GoogleAnalytics;
use Marshmallow\GoogleAnalytics\Contracts\GoogleAnalyticsEvent;
class OrderCreated implements GoogleAnalyticsEvent
{
//...
public function withAnalytics(GoogleAnalytics $analytics): GoogleAnalytics
{
//
}
}
class OrderCreated implements GoogleAnalyticsEvent
{
protected $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function withAnalytics(GoogleAnalytics $analytics): GoogleAnalytics
{
$ecommerce = (new EcommerceTracking)
->id($this->order->id)
->affiliation(env('APP_NAME'))
->revenue($this->order->revenue())
->shipping($this->order->shippingCost())
->tax($this->order->tax())
->currency('EUR');
return $analytics->ecommerceTracking($ecommerce);
}
}
$pageview = (new Pageview)
->hostname('marshmallow.dev')
->page('/home')
->title('homepage');
(new GoogleAnalytics())
->version(1)
->trackingId(env('SEO_GA'))
->anonymousClientId()
->pageview($pageview)
/**
* Call the sendToGoogle method at the end
*/
sendToGoogle();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.