Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nystudio107/instantanalytics
DEPRECATED Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
https://github.com/nystudio107/instantanalytics
craft-commerce craft-plugin craftcms google-analytics google-measurement-protocol
Last synced: about 1 month ago
JSON representation
DEPRECATED Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
- Host: GitHub
- URL: https://github.com/nystudio107/instantanalytics
- Owner: nystudio107
- License: other
- Created: 2016-06-13T14:47:01.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-01T23:46:07.000Z (about 6 years ago)
- Last Synced: 2024-07-07T11:06:01.371Z (6 months ago)
- Topics: craft-commerce, craft-plugin, craftcms, google-analytics, google-measurement-protocol
- Language: PHP
- Homepage:
- Size: 2.78 MB
- Stars: 101
- Watchers: 10
- Forks: 4
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)
# DEPRECATED
This Craft CMS 2.x plugin is no longer supported, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.
The Craft CMS 3.x version of this plugin can be found here: [craft-instantanalytics](https://github.com/nystudio107/craft-instantanalytics) and can also be installed via the Craft Plugin Store in the Craft CP.
# Instant Analytics plugin for Craft CMS
Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
Related: [Instant Analytics for Craft 3.x](https://github.com/nystudio107/craft3-instantanalytics)
![Screenshot](resources/screenshots/ia_screenshot01.png)
## Installation
To install Instant Analytics, follow these steps:
1. Download & unzip the file and place the `instantanalytics` directory into your `craft/plugins` directory
2. -OR- do a `git clone https://github.com/nystudio107/instantanalytics.git` directly into your `craft/plugins` folder. You can then update it with `git pull`
3. -OR- install with Composer via `composer require nystudio107/instantanalytics`
4. Install plugin in the Craft Control Panel under Settings > Plugins
5. The plugin folder should be named `instantanalytics` for Craft to see it. GitHub recently started appending `-master` (the branch name) to the name of the folder for zip file downloads.Instant Analytics works on Craft 2.4.x, Craft 2.5.x, and Craft 2.6.x. It requires at least PHP 5.5 or later to work.
N.B.: Version 1.1 of Instant Analytics has breaking API changes from the 1.0.x version. You will need to add `{% hook 'iaSendPageView' %}` to your templates to send Google Analytics data. In addition, the Twig tags `sendEvent` and `sendPageView` are deprecated; instead use `eventAnalytics` and `pageViewAnalytics` respectively to return an `Analytics` object (see below).
## Instant Analytics Overview
Instant Analytics brings full Google Analytics support to your Twig templates and automatic Craft Commerce integration with Google Enhanced Ecommerce.
Instant Analytics also lets you track otherwise untrackable assets & events with Google Analytics, and eliminates the need for Javascript tracking.
You don't need to include the typical Google Analytics script tag on your pages, instead Instant Analytics will send page views when your front-end templates are rendered via the officially supported [Google Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/).
You can also track asset/media views in Google Analytics, either as PageViews or as Events. This lets you track otherwise untrackable things such as individual RSS feed accesses, images, PDF files, etc.
Instant Analytics is implemented on the demo site [Brads for Men](https://bradsformen.com)
## Use Cases
### Simple Page Tracking
If all you want is simple page tracking data sent to Google Analytics, Instant Analytics will do that for you automatically. Instant Analytics uses the [Google Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/) to send PageViews to your Google Analytics account the same way the Google Analytics Tracking Code Javascript tag does.
In addition, Instant Analytics injects an `instantAnalytics` object into your templates, which you can manipulate as you see fit, adding Google Analytics properties to be sent along with your PageView.
It has the added benefit of not having to load any Javascript on the front-end to do this, which results in the following benefits:
* Your pages will render quicker in-browser, with no external resources loaded just for PageView tracking
* Pages will be tracked even if the client's browser has Javascript disabled or blocked
* Javascript errors will not cause Google Analytics data to fail to be collected### Craft Commerce Integration with Google Enhanced Ecommerce
If you are using Craft Commerce, Instant Analytics will recognize this, and automatically send Google Enhanced Ecommerce data for the following actions:
* **Add to Cart** - When someone adds an item from your Craft Commerce store to their cart. This will include data for the Product or Variant that was added to the cart.
* **Remove from Cart** - When someone removes an item from your Craft Commerce store cart (requires Craft Commerce 1.2.x or later). This will include data for the Product or Variant that was removed from the cart.
* **Purchase** - When someone completes a purchase in your Craft Commerce store. This will include all of the LineItems that were added to the cart, as well as the TransactionID, Revenue, Tax, Shipping, and Coupon Code used (if any).Additionally, you can add simple Twig tags to your templates to track Product Impressions, Product Detail Views, and track each step of the Checkout process. In Google Analytics, you will be able to view detailed information on the sales from your Craft Commerce store, and other useful information such as where customers are abandoning their cart in the Checkout process.
### Tracking Assets/Resources
Instant Analytics lets you track assets/resources that you can't normally track. For instance, you may have a collection of PDF documents that you'd like to know when they are viewed.
Using a simple `{{ pageViewTrackingUrl(myAsset.url, myAsset.title) }}` or `{{ eventTrackingUrl(myAsset.url, myAsset.title, "action", "label", "value") }}` Twig function, Instant Analytics will generate a public URL that will register a PageView in Google Analytics for the asset/resource, and then display or download the asset/resource.
### Tracking RSS Feeds
Getting actual tracking statistics on RSS feeds can be notoriously difficult, because they are often consumed by clients that are not web browsers, and therefor will not run Javascript tracking code.
With Instant Analytics, if your RSS feed is a Twig template, accesses will automatically be tracked. Additionally, you can use the `{{ pageViewTrackingUrl(myAsset.url, myAsset.title) }}` or `{{ eventTrackingUrl(myAsset.url, myAsset.title, "action", "label", "value") }}` Twig functions to track individual episode accesses in Google Analytics.
### Custom Tracking via Twig or Plugin
If your needs are more specialized, Instant Analytics will give your Twig templates or plugin full access to an `Analytics` object that allows you to send arbitrary Google Analytics tracking data to Google Analytics.
You can do anything from customized PageViews to complicated Google Enhanced eCommerce tracking,
## Configuring Instant Analytics
Once you have installed Instant Analytics, you'll see a welcome screen. Click on **Get Started** to configure Instant Analytics:
* **Google Analytics Tracking ID:** Enter your Google Analytics Tracking ID here. Only enter the ID, e.g.: UA-XXXXXX-XX, not the entire script code.
* **Strip Query String from PageView URLs:** If this setting is on, the query string will be stripped from PageView URLs before being sent to Google Analytics. e.g.: `/some/path?token=1235312` would be sent as just `/some/path`
* **Auto Send "Add To Cart" Events:** If this setting is on, Google Analytics Enhanced Ecommerce events are automatically sent when an item is added to your Craft Commerce cart.
* **Auto Send "Remove From Cart" Events:** If this setting is on, Google Analytics Enhanced Ecommerce events are automatically sent when an item is removed from your Craft Commerce cart.
* **Auto Send "Purchase Complete" Events:** If this setting is on, Google Analytics Enhanced Ecommerce events are automatically sent a purchase is completed.
* **Commerce Product Category Field:** Choose the field in your Product or Variant field layout that should be used for the product's Category field for Google Analytics Enhanced Ecommerce
* **Commerce Product Brand Field** Choose the field in your Product or Variant field layout that should be used for the product's Brand field for Google Analytics Enhanced EcommerceIf you have the [SEOmatic](https://github.com/nystudio107/seomatic) plugin installed, Instant Analytics will automatically grab your **Google Analytics Tracking ID:** from it.
**NOTE:** Instant Analytics will work with the traditional Google Analytics Tracking Code Javascript tag; it's not an either/or, they can coexist. Instant Analytics is just a different way to send the same data to Google Analytics.
However, to prevent duplicate data from being sent, if you use Instant Analytics to send PageView data, you should turn off the Javascript sending PageViews automatically by:
* In [SEOmatic](https://github.com/nystudio107/seomatic) turn off **Automatically send Google Analytics PageView**
* If you don't use SEOmatic, remove the line `ga('send', 'pageview');` from your Google Analytics Tracking Code Javascript tagThen you can still use the `ga()` calls to send events to Google Analytics. Or, if you don't send events via Javascript, you can just remove the Google Analytics tag/Javascript from your page entirely.
### Customizing via the config.php file
Instant Analytics has a number of other configuration options that can be customized on a per-environment basis via the `config.php` file. Don't edit this file, instead copy it to `craft/config` as `instantanalytics.php` (rename it) and make your changes there.
## Using Instant Analytics
### Simple Page Tracking
Once you've entered your **Google Analytics Tracking ID** you just need to add a call to `{% hook 'iaSendPageView' %}` to your front-end templates to send PageView tracking to Google Analytics. We recommend that you do this in a block at the bottom of your `layout.twig` template that other templates extend, right before the `