initial
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
### 2.4.1 | 2026-03-03
|
||||
- Added the ability to automatically output scripts when using Manual Configuration.
|
||||
- Updated the add-on to use the new [versioning system](https://docs.gravityforms.com/version-numbering/).
|
||||
- Fixed an unexpected redirect when a user tries to complete the setup without selecting a connection type.
|
||||
|
||||
### 2.4.0 | 2025-06-18
|
||||
- Added a new [`gform_googleanalytics_mp_session_id`](https://docs.gravityforms.com/gform_googleanalytics_mp_session_id/) filter to allow for custom session ID handling.
|
||||
- Updated session ID handling in Measurement Protocol to use the updated GA4 cookie format.
|
||||
- Fixed an issue where form submissions fail when using the new AJAX submission method.
|
||||
- Fixed an issue where pagination events aren't sent with Google Measurement Protocol using the new AJAX submission method.
|
||||
|
||||
### 2.3.0 | 2024-07-02
|
||||
- Added the session ID to the event data sent to Google Analytics when using Google Measurement Protocol.
|
||||
- Fixed an issue where the result of sending an event to Google might not be written to the log when triggered by a non-logged in user.
|
||||
|
||||
### 2.2.0 | 2024-02-07
|
||||
- Added support for the {source_page_number} and {current_page_number} merge tags in pagination settings.
|
||||
- Fixed a link on the plugin settings page.
|
||||
- Fixed a timeout error that occurs when using the http_request_timeout filter.
|
||||
- Removed unused Universal Analytics code that is no longer relevant to GA4.
|
||||
|
||||
### 2.1.0 | 2023-09-06
|
||||
- Added improved logging for pagination and submission events.
|
||||
- Fixed an issue where confirmation redirect URLs with query string variables are getting improperly escaped, preventing the query string variables from being accessible on the confirmation page.
|
||||
- Fixed an issue where events can be incorrectly sent to tag manager using the selected trigger name rather than the trigger's event name.
|
||||
- Fixed an issue where the tracking ID is not included when loading gtag.js.
|
||||
- Fixed an issue where the gforms_google_analytics_frontend_strings variable is output multiple times.
|
||||
- Fixed an issue that causes scripts to output on REST submission requests.
|
||||
|
||||
### 2.0.0 | 2023-05-31
|
||||
- Added support for manually entering Google Analytics settings.
|
||||
- Added support for confirmations configured to redirect to another site.
|
||||
- Added support for console logging.
|
||||
- Added support for mapping UTM variables from URL when configuring Tag Manager feeds and pagination events.
|
||||
- Added methods for upgrading feeds to be compatible with Google Analytics 4.
|
||||
- Added validation for event parameters and values.
|
||||
- Updated the oAuth flow so that it uses the Google Analytics Admin API which is compatible with GA4.
|
||||
- Updated the feed settings to allow for sending up to 25 custom parameters.
|
||||
- Removed all goal based settings as goals will not work in GA4.
|
||||
|
||||
### 1.3 | 2023-05-11
|
||||
- Added additional logging to help troubleshoot sending events.
|
||||
- Added warning message about upcoming end of life for Google Universal Analytics API.
|
||||
- Disabled automatic updates for this version only since the update from 1.3 to 2.0 will require user interaction.
|
||||
|
||||
### 1.2 | 2022-12-22
|
||||
- Fixed an issue where the save settings button is disabled in languages other than English.
|
||||
- Added Gravity Forms license key to oAuth process.
|
||||
|
||||
### 1.1 | 2022-10-18
|
||||
- Added fallback methods for entering account information manually.
|
||||
- Fixed an issue where the Google Analytics query limit prevents displaying all of a user's accounts.
|
||||
- Fixed an issue where forms embedded with ajax will not send events using the Google Analytics connection method without an event value.
|
||||
|
||||
### 1.0 | 2022-06-15
|
||||
- Added an option to manually configure the Analytics account in Google Tag Manager so GA4 accounts can be used without an associated UA account.
|
||||
- Updated error messages to be more informative when API calls fail.
|
||||
- Fixed an issue where goals can't be created due to duplicate IDs.
|
||||
|
||||
### 1.0-rc-1 | 2022-02-23
|
||||
- Updated error message styling to be compatible with Gravity Forms 2.6.
|
||||
- Updated error messages when API calls fail.
|
||||
- Fixed an issue where events are potentially duplicated when sending via ajax.
|
||||
|
||||
### 1.0-beta-1 | 2022-01-12
|
||||
- All new!
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: Gravity Forms Google Analytics Add-On
|
||||
Plugin URI: http://gravityforms.com
|
||||
Description: Integrates Gravity Forms with Google Analytics and Tag Manager
|
||||
Version: 2.4.1
|
||||
Author: Gravity Forms
|
||||
Author URI: https://gravityforms.com
|
||||
License: GPL-3.0+
|
||||
Text Domain: gravityformsgoogleanalytics
|
||||
Domain Path: /languages
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Copyright 2019-2025 Rocketgenius Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see http://www.gnu.org/licenses.
|
||||
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
use Gravity_Forms\Gravity_Forms_Google_Analytics\GF_Google_Analytics;
|
||||
|
||||
// Defines the current version of the Gravity Forms Google Analytics Add-On.
|
||||
define( 'GF_GOOGLE_ANALYTICS_VERSION', '2.4.1' );
|
||||
|
||||
// Defines the minimum version of Gravity Forms required to run Gravity Forms Google Analytics.
|
||||
define( 'GF_GOOGLE_ANALYTICS_MIN_GF_VERSION', '2.5.7' );
|
||||
|
||||
// Allow advanced users to change the Gravity Forms Google Analytics Add-on API location.
|
||||
// This will allow others to use their own Google Analytics API account to process conversions and permissions.
|
||||
if ( ! defined( 'GF_GOOGLE_ANALYTICS_GA_AUTH_API' ) ) {
|
||||
define( 'GF_GOOGLE_ANALYTICS_GA_AUTH_API', 'https://dev.gravityapi.com/wp-json/gravityapi/v1/auth/googleanalytics' );
|
||||
}
|
||||
|
||||
// After GF is loaded, load the add-on.
|
||||
add_action( 'gform_loaded', array( 'GF_Google_Analytics_Bootstrap', 'load_addon' ), 5 );
|
||||
|
||||
/**
|
||||
* Loads the Gravity Forms Google Analytics Add-On.
|
||||
*
|
||||
* Includes the main class and registers it with GFAddOn.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class GF_Google_Analytics_Bootstrap {
|
||||
|
||||
/**
|
||||
* Loads the required files.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public static function load_addon() {
|
||||
|
||||
// Requires the class file.
|
||||
require_once plugin_dir_path( __FILE__ ) . '/class-gf-google-analytics.php';
|
||||
|
||||
// Registers the class name with GFAddOn.
|
||||
GFAddOn::register( 'Gravity_Forms\Gravity_Forms_Google_Analytics\GF_Google_Analytics' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the GF_Google_Analytics class
|
||||
*
|
||||
* @since 1.0
|
||||
* @return GF_Google_Analytics An instance of the GF_Google_Analytics class
|
||||
*/
|
||||
function gf_google_analytics() {
|
||||
if ( class_exists( 'Gravity_Forms\Gravity_Forms_Google_Analytics\GF_Google_Analytics' ) ) {
|
||||
return GF_Google_Analytics::get_instance();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 2195.9 2430.9" style="enable-background:new 0 0 2195.9 2430.9;" xml:space="preserve">
|
||||
<g>
|
||||
<path fill="#F9AB00" d="M2195.9,2126.7c0.9,166.9-133.7,302.8-300.5,303.7c-12.4,0.1-24.9-0.6-37.2-2.1
|
||||
c-154.8-22.9-268.2-157.6-264.4-314V316.1c-3.7-156.6,110-291.3,264.9-314c165.7-19.4,315.8,99.2,335.2,264.9
|
||||
c1.4,12.2,2.1,24.4,2,36.7L2195.9,2126.7z"/>
|
||||
<path fill="#E37400" d="M301.1,1828.7c166.3,0,301.1,134.8,301.1,301.1c0,166.3-134.8,301.1-301.1,301.1
|
||||
C134.8,2430.9,0,2296.1,0,2129.8C0,1963.5,134.8,1828.7,301.1,1828.7z M1093.3,916.2c-167.1,9.2-296.7,149.3-292.8,316.6v808.7
|
||||
c0,219.5,96.6,352.7,238.1,381.1c163.3,33.1,322.4-72.4,355.5-235.7c4.1-20,6.1-40.3,6-60.7v-907.4
|
||||
c0.3-166.9-134.7-302.4-301.6-302.7C1096.8,916.1,1095,916.1,1093.3,916.2z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="matrix(1, 0, 0, 1, 27.009001, -39.238998)">
|
||||
<path fill="#4285F4" d="M -3.264 51.509 C -3.264 50.719 -3.334 49.969 -3.454 49.239 L -14.754 49.239 L -14.754 53.749 L -8.284 53.749 C -8.574 55.229 -9.424 56.479 -10.684 57.329 L -10.684 60.329 L -6.824 60.329 C -4.564 58.239 -3.264 55.159 -3.264 51.509 Z"/>
|
||||
<path fill="#34A853" d="M -14.754 63.239 C -11.514 63.239 -8.804 62.159 -6.824 60.329 L -10.684 57.329 C -11.764 58.049 -13.134 58.489 -14.754 58.489 C -17.884 58.489 -20.534 56.379 -21.484 53.529 L -25.464 53.529 L -25.464 56.619 C -23.494 60.539 -19.444 63.239 -14.754 63.239 Z"/>
|
||||
<path fill="#FBBC05" d="M -21.484 53.529 C -21.734 52.809 -21.864 52.039 -21.864 51.239 C -21.864 50.439 -21.724 49.669 -21.484 48.949 L -21.484 45.859 L -25.464 45.859 C -26.284 47.479 -26.754 49.299 -26.754 51.239 C -26.754 53.179 -26.284 54.999 -25.464 56.619 L -21.484 53.529 Z"/>
|
||||
<path fill="#EA4335" d="M -14.754 43.989 C -12.984 43.989 -11.404 44.599 -10.154 45.789 L -6.734 42.369 C -8.804 40.429 -11.514 39.239 -14.754 39.239 C -19.444 39.239 -23.494 41.939 -25.464 45.859 L -21.484 48.949 C -20.534 46.099 -17.884 43.989 -14.754 43.989 Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 2469.7 2469.8" style="enable-background:new 0 0 2469.7 2469.8;" xml:space="preserve">
|
||||
<g>
|
||||
<path fill="#8AB4F8" d="M1449.8,2376L1021,1946.7l921.1-930.5l436.7,436.6L1449.8,2376z"/>
|
||||
<path fill="#4285F4" d="M1452.9,527.1L1016.3,90.4L90.5,1016.2c-120.6,120.5-120.7,315.8-0.2,436.4c0.1,0.1,0.2,0.2,0.2,0.2
|
||||
l925.8,925.8l428.3-430.3L745,1235.1L1452.9,527.1z"/>
|
||||
<path fill="#8AB4F8" d="M2378.7,1016.2L1452.9,90.4c-120.6-120.6-316.1-120.6-436.7,0c-120.6,120.6-120.6,316.1,0,436.6l926.3,925.8
|
||||
c120.6,120.6,316.1,120.6,436.6,0c120.6-120.6,120.6-316.1,0-436.6L2378.7,1016.2z"/>
|
||||
<circle fill="#246FDB" cx="1231.2" cy="2163.9" r="306"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 917 B |
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="12.5 15.63 50 46.67">
|
||||
<title>cog</title>
|
||||
<path fill="#9092b0" d="M57.167 32.625c2.333-0.833 4.833 0.833 5.167 3.167 0.167 1 0.167 2.167 0.167 3.167s0 2.167-0.5 3.167c-0.167 2-1.833 3.5-3.833 3.5-0.5 0-0.833 0-1.333-0.167-1.167-0.5-2.333 0.167-2.833 1.167s-1.167 2.167-1.833 3.167c-0.667 1-0.5 2.333 0.333 3s1.333 1.833 1.333 3c0 1.167-0.5 2.333-1.5 3-1.667 1.333-3.5 2.333-5.333 3.167-0.5 0.167-1 0.333-1.5 0.333-1.833 0-3.5-1.333-3.833-3.167-0.167-1.167-1.333-2-2.5-1.833s-2.5 0.167-3.667 0c-1.333-0.167-2.333 0.667-2.5 1.833-0.333 1.833-2 3.167-3.833 3.167-0.5 0-1-0.167-1.5-0.333-1.833-0.833-3.667-1.833-5.333-3.167-0.833-0.667-1.5-1.833-1.5-3s0.5-2.333 1.333-3c0.833-0.667 1-2 0.333-3s-1.333-2-1.833-3.167c-0.5-1.167-1.833-1.667-2.833-1.333-2.333 0.833-4.833-0.833-5.167-3.167-0.167-1-0.167-2.167-0.167-3.167s0-2.167 0.167-3.167c0.167-2 1.833-3.5 3.833-3.5 0.5 0 0.833 0 1.333 0.167 1.167 0.5 2.333-0.167 2.833-1.167s1.167-2.167 1.833-3.167c0.833-1 0.667-2.167-0.333-3-0.833-0.667-1.333-1.833-1.333-3s0.667-2.333 1.5-3c1.667-1.333 3.5-2.333 5.5-3.167 0.5-0.167 1-0.333 1.5-0.333 1.833 0 3.5 1.333 3.833 3.167 0.167 1.167 1.333 2 2.5 1.833s2.5-0.167 3.667 0c1.333 0.167 2.333-0.667 2.5-1.833 0.333-1.833 2-3.167 3.833-3.167 0.396 0 0.791 0.104 1.27 0.23 0.126 0.033 0.258 0.068 0.397 0.103 1.833 0.833 3.667 1.833 5.333 3.167 0.833 0.667 1.5 1.833 1.5 3s-0.5 2.333-1.333 3.167c-0.833 0.667-1 2-0.333 3v0c0.667 1 1.333 2 1.833 3.167 0.5 1 1.833 1.5 2.833 1.167zM37.502 47.292c4.667 0 8.333-3.667 8.333-8.333s-3.667-8.333-8.333-8.333c-4.667 0-8.333 3.667-8.333 8.333s3.667 8.333 8.333 8.333z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
+369
@@ -0,0 +1,369 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms_Google_Analytics;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
use WP_Error;
|
||||
/**
|
||||
* Gravity Forms Google Analytics Add-On.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package GravityForms
|
||||
* @author Rocketgenius
|
||||
* @copyright Copyright (c) 2019, Rocketgenius
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helper class for retrieving the Google Analytics API validation.
|
||||
*/
|
||||
class GF_Google_Analytics_API {
|
||||
|
||||
/**
|
||||
* Google Analytics API URL.
|
||||
*
|
||||
* @since 1.0
|
||||
* @var string $ga_api_url Google Analytics API URL.
|
||||
*/
|
||||
protected $ga_api_url = 'https://www.googleapis.com/analytics/v3/';
|
||||
|
||||
/**
|
||||
* Google Analytics Admin API URL.
|
||||
*
|
||||
* @since 2.0
|
||||
* @var string $ga_admin_api_url Google Analytics Admin API URL.
|
||||
*/
|
||||
protected $ga_admin_api_url = 'https://analyticsadmin.googleapis.com/v1beta/';
|
||||
|
||||
/**
|
||||
* Google Tag Manager API URL.
|
||||
*
|
||||
* @since 1.0
|
||||
* @var string $gtm_api_url Google Tag Manager API URL.
|
||||
*/
|
||||
protected $gtm_api_url = 'https://www.googleapis.com/tagmanager/v2/';
|
||||
|
||||
/**
|
||||
* Google Analytics API token.
|
||||
*
|
||||
* @since 1.0
|
||||
* @var string $token Google Analytics Token.
|
||||
*/
|
||||
protected $token = null;
|
||||
|
||||
/**
|
||||
* Add-on instance.
|
||||
*
|
||||
* @var GF_Google_Analytics
|
||||
*/
|
||||
private $addon;
|
||||
|
||||
/**
|
||||
* Initialize API library.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param GF_Google_Analytics $addon GF_Google_Analytics instance.
|
||||
* @param string $token Google Analytics API token.
|
||||
*/
|
||||
public function __construct( $addon, $token = null ) {
|
||||
$this->token = $token;
|
||||
$this->addon = $addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make API request.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param string $path Request path.
|
||||
* @param string $mode ga or gtm for Google Analytics or Tag Manager.
|
||||
* @param array $body Body arguments.
|
||||
* @param string $method Request method. Defaults to GET.
|
||||
* @param string $return_key Array key from response to return. Defaults to null (return full response).
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
private function make_request( $path = '', $mode = 'ga', $body = array(), $method = 'GET', $return_key = null ) {
|
||||
|
||||
// Log API call succeed.
|
||||
gf_google_analytics()->log_debug( __METHOD__ . '(): Making request to: ' . $path );
|
||||
|
||||
// Get API Key.
|
||||
$token = $this->token;
|
||||
|
||||
// Get mode.
|
||||
$api_url = '';
|
||||
switch ( $mode ) {
|
||||
case 'ga4':
|
||||
$api_url = $this->ga_admin_api_url;
|
||||
break;
|
||||
case 'ga':
|
||||
$api_url = $this->ga_api_url;
|
||||
break;
|
||||
case 'gtm':
|
||||
$api_url = $this->gtm_api_url;
|
||||
break;
|
||||
default:
|
||||
return new WP_Error( 'google_analytics_invalid_mode', esc_html__( 'The API mode supplied is not supported by the Google Analytics API.', 'gravityformsgoogleanalytics' ), array() );
|
||||
}
|
||||
|
||||
// Build request URL.
|
||||
$request_url = $api_url . $path;
|
||||
|
||||
$args = array(
|
||||
'method' => $method,
|
||||
/**
|
||||
* Filters if SSL verification should occur.
|
||||
*
|
||||
* @param bool false If the SSL certificate should be verified. Defaults to false.
|
||||
* @param string $request_url The request URL.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false, $request_url ),
|
||||
/**
|
||||
* Sets the HTTP timeout, in seconds, for the request.
|
||||
*
|
||||
* @param int 30 The timeout limit, in seconds. Defaults to 30.
|
||||
* @param string $request_url The request URL.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
'timeout' => apply_filters( 'http_request_timeout', 30, $request_url ),
|
||||
);
|
||||
if ( 'GET' === $method || 'POST' === $method || 'PUT' === $method ) {
|
||||
$args['body'] = empty( $body ) ? '' : $body;
|
||||
$args['headers'] = array(
|
||||
'Authorization' => 'Bearer ' . $token,
|
||||
'Accept' => 'application/json;ver=1.0',
|
||||
'Content-Type' => 'application/json; charset=UTF-8',
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'POST' === $method ) {
|
||||
$args['body'] = wp_json_encode( $body );
|
||||
}
|
||||
|
||||
// Execute request.
|
||||
$response = wp_remote_request(
|
||||
$request_url,
|
||||
$args
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response_body = gf_google_analytics()->maybe_decode_json( wp_remote_retrieve_body( $response ) );
|
||||
$retrieved_response_code = $response['response']['code'];
|
||||
|
||||
if ( 200 !== $retrieved_response_code ) {
|
||||
$error_message = rgars( $response_body, 'error/message', "Expected response code: 200. Returned response code: {$retrieved_response_code}." );
|
||||
$error_code = rgars( $response_body, 'error/errors/reason', 'google_analytics_api_error' );
|
||||
|
||||
gf_google_analytics()->log_error( __METHOD__ . '(): Unable to validate with the Google Analytics API: ' . $error_message );
|
||||
|
||||
return new WP_Error( $error_code, $error_message, $retrieved_response_code );
|
||||
}
|
||||
|
||||
return $response_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a refresh token when the original expires.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $refresh_token Refresh token to re-authorize.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function refresh_token( $refresh_token ) {
|
||||
// Connect to Gravity Form's API.
|
||||
$response = wp_remote_post(
|
||||
$this->addon->get_gravity_api_url( '/auth/googleanalytics/refresh' ),
|
||||
array(
|
||||
'body' => array(
|
||||
'refresh_token' => rawurlencode( $refresh_token ),
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
$response_body = gf_google_analytics()->maybe_decode_json( wp_remote_retrieve_body( $response ) );
|
||||
|
||||
$retrieved_response_code = $response['response']['code'];
|
||||
if ( 200 !== absint( $retrieved_response_code ) || ! rgars( $response_body, 'token/access_token' ) ) {
|
||||
$error_message = "Expected response code: 200. Returned response code: {$retrieved_response_code}.";
|
||||
|
||||
gf_google_analytics()->log_error( __METHOD__ . '(): Unable to Reauthorize refresh token: ' . $error_message );
|
||||
gf_google_analytics()->log_error( __METHOD__ . '(): Response body: ' . var_export( $response_body, true ) );
|
||||
|
||||
return new WP_Error( 'google_analytics_api_error', $error_message, $retrieved_response_code );
|
||||
}
|
||||
return $response_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of Google Analytics accounts.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_ga4_accounts() {
|
||||
return $this->make_request(
|
||||
'accountSummaries',
|
||||
'ga4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of GA4 data streams.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $property GA4 property associated with the data streams. In the format "property/XXXX".
|
||||
*
|
||||
* @return array|WP_Error Returns an array of data streams.
|
||||
*/
|
||||
public function get_data_streams( $property ) {
|
||||
return $this->make_request(
|
||||
"{$property}/dataStreams",
|
||||
'ga4',
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Measurement Protocol API Secret.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $path The path to the data stream for which we're creating a secret.
|
||||
*
|
||||
* @return array|WP_Error Returns an array of measurement protocol secrets.
|
||||
*/
|
||||
public function create_api_secret( $path ) {
|
||||
return $this->make_request(
|
||||
$path . '/measurementProtocolSecrets',
|
||||
'ga4',
|
||||
array(
|
||||
'displayName' => 'GravityFormsSecret',
|
||||
),
|
||||
'POST'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Measurement Protocol API Secrets.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $path The path to the data stream for which we're retrieving secrets.
|
||||
*
|
||||
* @return array|WP_Error Returns an array of measurement protocol secrets.
|
||||
*/
|
||||
public function get_api_secrets( $path ) {
|
||||
return $this->make_request(
|
||||
$path . '/measurementProtocolSecrets',
|
||||
'ga4',
|
||||
array(),
|
||||
'GET'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tag manager accounts.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $body Body information.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_tag_manager_account( $body ) {
|
||||
return $this->make_request(
|
||||
'accounts',
|
||||
'gtm',
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tag manager containers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $body Body information.
|
||||
* @param string $account_id Account to retrieve containers for.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_tag_manager_containers( $body, $account_id ) {
|
||||
return $this->make_request(
|
||||
sprintf( 'accounts/%s/containers', $account_id ),
|
||||
'gtm',
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tag manager workspaces.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $body Body information.
|
||||
* @param string $path Account path to request.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_tag_manager_workspaces( $body, $path ) {
|
||||
return $this->make_request(
|
||||
sprintf( '%s/workspaces', $path ),
|
||||
'gtm',
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tag manager triggers.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $body Body information.
|
||||
* @param string $path Account path to request.
|
||||
* @param string $workspace The workspace to retrieve variables for.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_tag_manager_triggers( $body, $path, $workspace ) {
|
||||
return $this->make_request(
|
||||
sprintf( '%s/workspaces/%s/triggers', $path, $workspace ),
|
||||
'gtm',
|
||||
$body
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of tag manager variables.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $body Body information.
|
||||
* @param string $path Account path to request.
|
||||
* @param string $workspace The workspace to retrieve variables for.
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get_tag_manager_variables( $body, $path, $workspace ) {
|
||||
return $this->make_request(
|
||||
sprintf( '%s/workspaces/%s/variables', $path, $workspace ),
|
||||
'gtm',
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms_Google_Analytics;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
use GFFormsModel;
|
||||
|
||||
/**
|
||||
* Gravity Forms Google Analytics Measurement Protocol.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package GravityForms
|
||||
* @author Rocketgenius
|
||||
* @copyright Copyright (c) 2019, Rocketgenius
|
||||
*/
|
||||
class GF_Google_Analytics_Measurement_Protocol {
|
||||
/**
|
||||
* The Endpoint for the Measurement Protocol
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $endpoint The Measurement Protocol endpoint.
|
||||
*/
|
||||
//private $endpoint = 'https://www.google-analytics.com/debug/mp/collect?'; // Debug endpoint.
|
||||
private $endpoint = 'https://www.google-analytics.com/mp/collect?';
|
||||
|
||||
/**
|
||||
* The Client ID for the Measurement Protocol
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $cid The Client ID.
|
||||
*/
|
||||
private $cid = '';
|
||||
|
||||
/**
|
||||
* The Measurement Protocol hit type
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $t Hit Type.
|
||||
*/
|
||||
private $t = 'event';
|
||||
|
||||
/**
|
||||
* The document path
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $dp The document path.
|
||||
*/
|
||||
private $dp = '';
|
||||
|
||||
/**
|
||||
* The document location
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $dl The document location.
|
||||
*/
|
||||
private $dl = '';
|
||||
|
||||
/**
|
||||
* The document title
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $dt The document title.
|
||||
*/
|
||||
private $dt = '';
|
||||
|
||||
/**
|
||||
* The document host name
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $dh The document host name.
|
||||
*/
|
||||
private $dh = '';
|
||||
|
||||
/**
|
||||
* The IP Address of the user.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $uip The IP Address of the user.
|
||||
*/
|
||||
private $uip = '';
|
||||
|
||||
/**
|
||||
* The API secret for sending events.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var string $api_secret The API secret
|
||||
*/
|
||||
private $api_secret = '';
|
||||
|
||||
/**
|
||||
* The Submission Parameters for the feed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var array $parameters The submission parameters
|
||||
*/
|
||||
private $parameters = array();
|
||||
|
||||
/**
|
||||
* The name for the event.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var bool $event_name The event name to be sent to Google Analytics.
|
||||
*/
|
||||
private $event_name = '';
|
||||
|
||||
/**
|
||||
* Init function. Attempts to get the client's CID
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function init( $api_secret, $event_name = 'gform_submission' ) {
|
||||
$this->cid = $this->create_client_id();
|
||||
$this->api_secret = $api_secret;
|
||||
$this->event_name = $event_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom event parameters
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $parameters The user's IP address.
|
||||
*/
|
||||
public function set_params( $parameters ) {
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the custom event parameters.
|
||||
*
|
||||
* @since 2.3
|
||||
*
|
||||
* @return array Returns the custom event parameters.
|
||||
*/
|
||||
public function get_params() {
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the User's IP
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $user_ip The user's IP address.
|
||||
*/
|
||||
public function set_user_ip_address( $user_ip ) {
|
||||
$this->uip = $user_ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the document path
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $document_path The path of the document.
|
||||
*/
|
||||
public function set_document_path( $document_path ) {
|
||||
$this->dp = $document_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the document host
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $document_host The host of the document.
|
||||
*/
|
||||
public function set_document_host( $document_host ) {
|
||||
$this->dh = $document_host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the document location
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $document_location The location of the document.
|
||||
*/
|
||||
public function set_document_location( $document_location ) {
|
||||
$this->dl = $document_location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the document title
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $document_title The document title for the page being submitted.
|
||||
*/
|
||||
public function set_document_title( $document_title ) {
|
||||
$this->dt = $document_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the data to the measurement protocol
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $ua_code The UA code to send the event to.
|
||||
* @param string $event_name The event name to be used.
|
||||
*/
|
||||
public function send( $google_analytics_code ) {
|
||||
|
||||
// Get variables in wp_remote_post body format.
|
||||
$user_properties_vars = array( 'dp', 'dl', 'dt', 'dh', 'uip' );
|
||||
$user_properties = array();
|
||||
foreach ( $user_properties_vars as $key => $user_properties_var ) {
|
||||
if ( empty( $this->{ $user_properties_vars[ $key ] } ) ) {
|
||||
// Empty params cause the payload to fail in testing.
|
||||
continue;
|
||||
}
|
||||
$user_properties[ $user_properties_var ] = $this->{$user_properties_vars[ $key ]};
|
||||
}
|
||||
|
||||
$session_id = $this->get_browser_session_id( $google_analytics_code );
|
||||
|
||||
if ( $session_id ) {
|
||||
$this->parameters['session_id'] = $session_id;
|
||||
}
|
||||
|
||||
$url = $this->endpoint . 'measurement_id=' . $google_analytics_code . '&api_secret=' . $this->api_secret;
|
||||
|
||||
$body = array(
|
||||
'client_id' => $this->cid,
|
||||
'events' => array(
|
||||
'name' => $this->event_name,
|
||||
'params' => $this->parameters,
|
||||
),
|
||||
);
|
||||
|
||||
gf_google_analytics()->log_debug( __METHOD__ . '(): Sending data to Google Analytics Measurement Protocol. URL (last 4 of api_secret only): ' . substr( $url, 0, strpos( $url, 'api_secret=' ) + 11 ) . 'XXXXXXX' . substr( $url, -4 ) . ' - Body: ' . print_r( $body, true ) );
|
||||
|
||||
// Perform the POST.
|
||||
return wp_remote_post(
|
||||
$url,
|
||||
array(
|
||||
'body' => wp_json_encode( $body ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a GUID on Client specific values
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string New Client ID.
|
||||
*/
|
||||
private function create_client_id() {
|
||||
|
||||
// collect user specific data.
|
||||
if ( isset( $_COOKIE['_ga'] ) ) {
|
||||
|
||||
$ga_cookie = explode( '.', sanitize_text_field( wp_unslash( $_COOKIE['_ga'] ) ) );
|
||||
if ( isset( $ga_cookie[2] ) ) {
|
||||
|
||||
// check if uuid.
|
||||
if ( $this->check_uuid( $ga_cookie[2] ) ) {
|
||||
|
||||
// uuid set in cookie.
|
||||
return $ga_cookie[2];
|
||||
} elseif ( isset( $ga_cookie[2] ) && isset( $ga_cookie[3] ) ) {
|
||||
|
||||
// google default client id.
|
||||
return $ga_cookie[2] . '.' . $ga_cookie[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nothing found - return random uuid client id.
|
||||
return GFFormsModel::get_uuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session id.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 2.4.0 added support for the GS2 cookie format.
|
||||
*
|
||||
* @param string $measurement_id The measurement id.
|
||||
*
|
||||
* @return string|null The session id.
|
||||
*/
|
||||
private function get_browser_session_id( $measurement_id ) {
|
||||
$session_id = null;
|
||||
|
||||
// Cookie name example: '_ga_1YS1VWHG3V'.
|
||||
$cookie_name = '_ga_' . str_replace( 'G-', '', $measurement_id );
|
||||
|
||||
if ( isset( $_COOKIE[ $cookie_name ] ) ) {
|
||||
$cookie_value = sanitize_text_field( wp_unslash( $_COOKIE[ $cookie_name ] ) );
|
||||
|
||||
// Check for the new GS2 cookie format.
|
||||
if ( str_contains( $cookie_value, '$' ) && preg_match( '/s(\d+)/', $cookie_value, $matches ) ) {
|
||||
$session_id = $matches[1];
|
||||
}
|
||||
|
||||
// Fallback to the dot delimited GS1 format.
|
||||
if ( ! $session_id ) {
|
||||
$parts = explode( '.', $cookie_value );
|
||||
if ( isset( $parts[3] ) && is_numeric( $parts[3] ) ) {
|
||||
$session_id = $parts[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the GA4 session ID used in Measurement Protocol requests.
|
||||
*
|
||||
* @param string|null $session_id Parsed session ID or null if not found.
|
||||
* @param string $cookie_name Name of the GA cookie used.
|
||||
* @param string $measurement_id GA4 Measurement ID.
|
||||
*/
|
||||
$session_id = apply_filters( 'gform_googleanalytics_mp_session_id', $session_id, $cookie_name, $measurement_id );
|
||||
|
||||
return $session_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if is a valid uuid v4
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $uuid The UUID to check.
|
||||
*
|
||||
* @return bool If the UUID is valid
|
||||
*/
|
||||
private function check_uuid( $uuid ) {
|
||||
return preg_match( '#^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$#i', $uuid );
|
||||
}
|
||||
}
|
||||
+573
@@ -0,0 +1,573 @@
|
||||
<?php
|
||||
/**
|
||||
* Object responsible for organizing and constructing the form settings page.
|
||||
*/
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms_Google_Analytics\Settings;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
use Gravity_Forms\Gravity_Forms_Google_Analytics\GF_Google_Analytics;
|
||||
use Gravity_Forms\Gravity_Forms\Settings\Settings;
|
||||
use GFCommon;
|
||||
use GFAddOn;
|
||||
use GFAPI;
|
||||
use GFFormsModel;
|
||||
use GFCache;
|
||||
|
||||
class Form_Settings {
|
||||
|
||||
/**
|
||||
* Add-on instance.
|
||||
*
|
||||
* @var GF_Google_Analytics
|
||||
*/
|
||||
private $addon;
|
||||
|
||||
/**
|
||||
* Defines the capability needed to access the Add-On form settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $_capabilities_form_settings The capability needed to access the Add-On form settings page.
|
||||
*/
|
||||
protected $_capabilities_form_settings = 'gravityforms_googleanalytics';
|
||||
|
||||
/**
|
||||
* Plugin_Settings constructor.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param GF_Google_Analytics $addon GF_Google_Analytics instance.
|
||||
*/
|
||||
public function __construct( $addon ) {
|
||||
$this->addon = $addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tab attributes so correct tab appears as selected.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array Array of tab attributes.
|
||||
*/
|
||||
public function get_tab_attributes() {
|
||||
$active_attrs = 'aria-selected=true class=active';
|
||||
$inactive_attrs = 'aria-selected=false';
|
||||
|
||||
$tab_attributes = array();
|
||||
|
||||
if ( rgget( 'settingstype' ) == 'form' ) {
|
||||
$tab_attributes['current_tab'] = 'form_settings';
|
||||
$tab_attributes['feed_link_attrs'] = $inactive_attrs;
|
||||
$tab_attributes['form_link_attrs'] = $active_attrs;
|
||||
} else {
|
||||
$tab_attributes['current_tab'] = 'feed';
|
||||
$tab_attributes['feed_link_attrs'] = $active_attrs;
|
||||
$tab_attributes['form_link_attrs'] = $inactive_attrs;
|
||||
}
|
||||
|
||||
return $tab_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the form settings page.
|
||||
*
|
||||
* This form settings page has tabs for the feed settings and the form settings.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $form the current form.
|
||||
*/
|
||||
public function form_settings_page( $form ) {
|
||||
|
||||
// Set up the data we need to display the tabs.
|
||||
$tab_attributes = $this->get_tab_attributes();
|
||||
|
||||
// Remove the feed id from the form settings url to ensure correct saving.
|
||||
$form_settings_params = $_GET;
|
||||
unset( $form_settings_params['fid'] );
|
||||
$feed_settings_url = http_build_query( array_merge( $_GET, array( 'settingstype' => 'feed' ) ) );
|
||||
$form_settings_url = http_build_query( array_merge( $form_settings_params, array( 'settingstype' => 'form' ) ) );
|
||||
|
||||
// Display the navigation tabs.
|
||||
echo '<nav class="gform-settings-tabs__navigation" role="tablist" style="margin-bottom:.875rem">
|
||||
<a role="tab" href="' . admin_url( 'admin.php?' . esc_html( $feed_settings_url ) ) . '" ' . esc_attr( $tab_attributes['feed_link_attrs'] ) . '>' . esc_html__( 'Feed Settings', 'gravityformsgoogleanalytics' ) . '</a>
|
||||
<a role="tab" href="' . admin_url( 'admin.php?' . esc_html( $form_settings_url ) ) . '" ' . esc_attr( $tab_attributes['form_link_attrs'] ) . '>' . esc_html__( 'Form Settings', 'gravityformsgoogleanalytics' ) . '</a>
|
||||
</nav>';
|
||||
|
||||
// Display the tab contents.
|
||||
if ( 'form_settings' == $tab_attributes['current_tab'] ) {
|
||||
|
||||
if ( ! $this->addon->can_create_feed() ) {
|
||||
printf( '<div>%s</div>', $this->addon->configure_addon_message() );
|
||||
return;
|
||||
}
|
||||
// Get fields.
|
||||
$sections = array_values( $this->addon->form_settings_fields( $form ) );
|
||||
$sections = $this->addon->prepare_settings_sections( $sections, 'form_settings' );
|
||||
$renderer = new Settings(
|
||||
array(
|
||||
'capability' => $this->_capabilities_form_settings,
|
||||
'fields' => $sections,
|
||||
'initial_values' => GF_Google_Analytics::get_instance()->get_form_settings( $form ),
|
||||
'save_callback' => function( $values ) use ( $form ) {
|
||||
$this->save_form_settings( $form, $values );
|
||||
},
|
||||
'before_fields' => function() use ( $form ) {
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
gform.addFilter( 'gform_merge_tags', 'addPaginationMergeTags' );
|
||||
|
||||
function addPaginationMergeTags( mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option ) {
|
||||
mergeTags[ 'other' ].tags.push( {
|
||||
tag: '{source_page_number}',
|
||||
label: <?php echo json_encode( __( 'Source Page Number', 'gravityforms' ) ) ?> } );
|
||||
mergeTags[ 'other' ].tags.push( {
|
||||
tag: '{current_page_number}',
|
||||
label: <?php echo json_encode( __( 'Current Page Number', 'gravityforms' ) ) ?> } );
|
||||
|
||||
return mergeTags;
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
},
|
||||
'after_fields' => function() use ( $form ) {
|
||||
|
||||
printf(
|
||||
'<script type="text/javascript">var form = %s;</script>',
|
||||
wp_json_encode( $form )
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
$renderer->render();
|
||||
} else {
|
||||
if ( $this->addon->is_detail_page() ) {
|
||||
// Feed edit page.
|
||||
$feed_id = $this->addon->get_current_feed_id();
|
||||
$this->addon->feed_edit_page( $form, $feed_id );
|
||||
} else {
|
||||
// Feed list UI.
|
||||
$this->addon->feed_list_page( $form );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Saves form settings to form object.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $form the current form.
|
||||
* @param array $settings the settings to save.
|
||||
*
|
||||
* @return true|false True on success or false on error
|
||||
*/
|
||||
public function save_form_settings( $form, $settings ) {
|
||||
$form[ $this->addon->get_slug() ] = $settings;
|
||||
$result = GFFormsModel::update_form_meta( $form['id'], $form );
|
||||
|
||||
return ! ( false === $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the settings which should be rendered on the feed edit page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_feed_settings_fields() {
|
||||
$form_id = rgget( 'id' );
|
||||
$form = GFAPI::get_form( $form_id );
|
||||
|
||||
return array(
|
||||
array(
|
||||
'title' => esc_html__( 'Feed Name', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'label' => esc_html__( 'Feed Name', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'text',
|
||||
'name' => 'feedName',
|
||||
'class' => 'medium',
|
||||
'required' => true,
|
||||
'tooltip' => '<strong>' . esc_html__( 'Feed Name', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Enter a feed name to uniquely identify this feed.', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'title' => esc_html__( 'Event Parameters', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => $this->get_ga4_event_fields( $form, 'feed' ),
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Conditional Logic Settings', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'conditionalLogic',
|
||||
'label' => esc_html__( 'Conditional Logic', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'feed_condition',
|
||||
'tooltip' => '<strong>' . __( 'Conditional Logic', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'When conditions are enabled, conversions will only be sent when the conditions are met.', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event parameter fieldmap field.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $form The current form object.
|
||||
* @param string $type Whether we're rendering feed or pagination fields.
|
||||
*
|
||||
* @return array Array of fields.
|
||||
*/
|
||||
public function get_ga4_event_fields( $form, $type ) {
|
||||
if ( $type !== 'pagination' && $type !== 'feed' ) {
|
||||
return;
|
||||
}
|
||||
$options = $this->addon->get_options();
|
||||
|
||||
$mode = rgar( $options, 'mode' );
|
||||
$prefix = ( $type === 'pagination' ) ? 'pagination_' : 'submission_';
|
||||
|
||||
if ( $mode !== 'gtm' ) {
|
||||
return array(
|
||||
array(
|
||||
'name' => $prefix . 'parameters',
|
||||
'description' => esc_html__( 'Parameter names must be 40 characters or fewer and are limited to alphanumeric characters and underscores. They cannot begin or end with an underscore. Values are limited to 100 characters or fewer.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Parameters', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'generic_map',
|
||||
'tooltip' => '<h6>' . esc_html__( 'Submission Parameters', 'gravityformsgoogleanalytics' ) . '</h6>' . esc_html__( 'Set the parameters that will be sent to Google Analytics for this feed.', 'gravityformsgoogleanalytics' ),
|
||||
'limit' => 25,
|
||||
'key_field' => array(
|
||||
'title' => esc_html__( 'Parameter Name', 'gravityformsgoogleanalytics' ),
|
||||
'allow_custom' => true,
|
||||
'placeholder' => esc_html__( 'Enter a parameter name', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
'value_field' => array(
|
||||
'title' => esc_html__( 'Parameter Value', 'gravityformsgoogleanalytics' ),
|
||||
'allow_custom' => true,
|
||||
'placeholder' => esc_html__( 'Enter a value', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
'validation_callback' => array( $this, 'custom_parameter_validation_callback' ),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
||||
$trigger_choices = $this->get_tag_manager_trigger_choices( $options );
|
||||
$variable_choices = $this->get_tag_manager_variable_choices( $options );
|
||||
|
||||
if ( empty( $trigger_choices ) ) {
|
||||
$trigger_setting = array(
|
||||
'name' => $prefix . 'trigger',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Tag Manager Trigger', 'gravityformsgoogleanalytics' ),
|
||||
'tooltip' => '<h6>' . esc_html__( 'Tag Manager Trigger', 'gravityformsgoogleanalytics' ) . '</h6>' . esc_html__( 'Set the trigger that will be sent to tag manager when this feed is processed.', 'gravityformsgoogleanalytics' ),
|
||||
'required' => true,
|
||||
);
|
||||
} else {
|
||||
$trigger_setting = array(
|
||||
'name' => $prefix . 'trigger',
|
||||
'type' => 'select_custom',
|
||||
'label' => esc_html__( 'Tag Manager Trigger', 'gravityformsgoogleanalytics' ),
|
||||
'choices' => $trigger_choices,
|
||||
'tooltip' => '<h6>' . esc_html__( 'Tag Manager Trigger', 'gravityformsgoogleanalytics' ) . '</h6>' . esc_html__( 'Set the trigger that will be sent to tag manager when this feed is processed.', 'gravityformsgoogleanalytics' ),
|
||||
'required' => true,
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
$trigger_setting,
|
||||
array(
|
||||
'name' => $prefix . 'parameters',
|
||||
'label' => esc_html__( 'Parameters', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'generic_map',
|
||||
'tooltip' => '<h6>' . esc_html__( 'Submission Parameters', 'gravityformsgoogleanalytics' ) . '</h6>' . esc_html__( 'Set the parameters that will be sent to Google Analytics for this feed.', 'gravityformsgoogleanalytics' ),
|
||||
'limit' => 25,
|
||||
'key_field' => array(
|
||||
'title' => esc_html__( 'Parameter Name', 'gravityformsgoogleanalytics' ),
|
||||
'allow_custom' => true,
|
||||
'placeholder' => esc_html__( 'Enter a parameter name', 'gravityformsgoogleanalytics' ),
|
||||
'choices' => $variable_choices,
|
||||
),
|
||||
'value_field' => array(
|
||||
'title' => esc_html__( 'Parameter Value', 'gravityformsgoogleanalytics' ),
|
||||
'allow_custom' => true,
|
||||
'placeholder' => esc_html__( 'Enter a value', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for validation the custom parameters.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param object $field The field being validated.
|
||||
* @param array $parameters The parameters being validated.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function custom_parameter_validation_callback( $field, $parameters ) {
|
||||
|
||||
foreach ( $parameters as $parameter ) {
|
||||
$key = 'gf_custom' === $parameter['key'] ? $parameter['custom_key'] : $parameter['key'];
|
||||
|
||||
if ( 'gf_custom' === $parameter['value'] ) {
|
||||
$value = $parameter['custom_value'];
|
||||
} else {
|
||||
$value = $parameter['value'];
|
||||
}
|
||||
|
||||
$field_error = $this->validate_parameter( $key, $value );
|
||||
|
||||
if ( $field_error ) {
|
||||
$this->addon->set_field_error( $field, $field_error );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter validation
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param string $key The parameter key.
|
||||
* @param string $value The parameter value.
|
||||
*
|
||||
* @return string The validation error.
|
||||
*/
|
||||
public function validate_parameter( $key, $value ) {
|
||||
if ( ! is_string( $key ) || ! is_string( $value ) ) {
|
||||
return esc_html__( 'Parameter names and values must be strings.', 'gravityformsgoogleanalytics' );
|
||||
}
|
||||
|
||||
if ( mb_strlen( $key ) > 40 ) {
|
||||
return esc_html__( 'Parameter names must be 40 characters or less.', 'gravityformsgoogleanalytics' );
|
||||
}
|
||||
|
||||
if ( mb_strlen( $value ) > 100 ) {
|
||||
return esc_html__( 'Parameter values must be 100 characters or less.', 'gravityformsgoogleanalytics' );
|
||||
}
|
||||
|
||||
if ( ! preg_match( '/^(?!_)[\w]*(?<!_)$/u', $key ) ) {
|
||||
return esc_html__( 'Parameter names cannot begin or end with an underscore, and must contain only letters, numbers, and underscores.', 'gravityformsgoogleanalytics' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag manager trigger choices.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $options The add-on's options.
|
||||
*
|
||||
* @return array Array of trigger choices.
|
||||
*/
|
||||
private function get_tag_manager_trigger_choices( $options ) {
|
||||
if ( rgar( $options, 'is_manual' ) === true ) {
|
||||
return array();
|
||||
}
|
||||
$trigger_choices = \GFCache::get( 'tag_manager_trigger_choices' );
|
||||
if ( $trigger_choices ) {
|
||||
return $trigger_choices;
|
||||
}
|
||||
|
||||
$ga4_account = rgar( $options, 'ga4_account' );
|
||||
$api_path = rgar( $ga4_account, 'gtm_api_path' );
|
||||
$workspace = rgar( $ga4_account, 'gtm_workspace_id' );
|
||||
$triggers = rgar( $this->addon->get_tag_manager_triggers( array(), $api_path, $workspace ), 'trigger' );
|
||||
|
||||
if ( is_wp_error( $triggers ) || empty( $triggers ) || ! is_array( $triggers ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$trigger_choices = array();
|
||||
foreach ( $triggers as $trigger ) {
|
||||
|
||||
$trigger_event_name = $this->get_trigger_event_name( $trigger );
|
||||
$trigger_choices[] = array(
|
||||
'label' => $trigger['name'],
|
||||
'value' => $trigger_event_name,
|
||||
);
|
||||
}
|
||||
\GFCache::set( 'tag_manager_trigger_choices', $trigger_choices );
|
||||
return $trigger_choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the trigger event name.
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @param array $trigger The trigger.
|
||||
*
|
||||
* @return string The trigger event name.
|
||||
*/
|
||||
private function get_trigger_event_name( $trigger ) {
|
||||
if ( $trigger['type'] !== 'customEvent' ) {
|
||||
return $trigger['name'];
|
||||
}
|
||||
|
||||
// There's no convenient api method to get this value, but it should always be in the same place for custom events.
|
||||
$event_name = rgars( $trigger, 'customEventFilter/0/parameter/1/value' );
|
||||
|
||||
if ( $event_name ) {
|
||||
return $event_name;
|
||||
} else {
|
||||
return $trigger['name'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag manager variable choices.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $options The add-on's options.
|
||||
*
|
||||
* @return array Array of variable choices.
|
||||
*/
|
||||
private function get_tag_manager_variable_choices( $options ) {
|
||||
if ( rgar( $options, 'is_manual' ) === true ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$variable_choices = \GFCache::get( 'tag_manager_variable_choices' );
|
||||
if ( $variable_choices ) {
|
||||
return $variable_choices;
|
||||
}
|
||||
|
||||
$ga4_account = rgar( $options, 'ga4_account' );
|
||||
$api_path = rgar( $ga4_account, 'gtm_api_path' );
|
||||
$workspace = rgar( $ga4_account, 'gtm_workspace_id' );
|
||||
|
||||
$variables = rgar( $this->addon->get_tag_manager_variables( array(), $api_path, $workspace ), 'variable' );
|
||||
$variable_choices = array();
|
||||
|
||||
if ( rgempty( $variables ) ) {
|
||||
return $variable_choices;
|
||||
}
|
||||
|
||||
foreach ( $variables as $variable ) {
|
||||
if ( rgar( $variable, 'type' ) !== 'v' ) {
|
||||
continue;
|
||||
}
|
||||
$variable_choices[] = array(
|
||||
'label' => $variable['name'],
|
||||
'value' => $this->get_variable_value( $variable ),
|
||||
);
|
||||
}
|
||||
\GFCache::set( 'tag_manager_variable_choices', $variable_choices );
|
||||
return $variable_choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the tag manager variable
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @param array $variable The variable from which to retrieve the value.
|
||||
*
|
||||
* @return string Returns the variable's value or a blank string if the variable isn't found.
|
||||
*/
|
||||
public function get_variable_value( $variable ) {
|
||||
foreach ( $variable['parameter'] as $parameter ) {
|
||||
if ( rgar( $parameter, 'key' ) === 'name' ) {
|
||||
return rgar( $parameter, 'value' );
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the columns for the feed page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function feed_list_columns() {
|
||||
$columns = array( 'feedName' => esc_html__( 'Name', 'gravityformsgoogleanalytics' ) );
|
||||
|
||||
if ( $this->addon->get_options( '', 'mode' ) == 'gtm' ) {
|
||||
$columns['submission_trigger'] = esc_html__( 'Trigger', 'gravityformsgoogleanalytics' );
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pagination form settings to Gravity Forms.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $form The form.
|
||||
*
|
||||
* @return array Updated form settings
|
||||
*/
|
||||
public function pagination_form_settings( $form ) {
|
||||
if ( rgget( 'settingstype' ) !== 'form' ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( isset( $form['pagination'] ) ) {
|
||||
return array(
|
||||
array(
|
||||
'title' => esc_html__( 'Form Settings', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'google_analytics_pagination',
|
||||
'label' => esc_html__( 'Pagination Tracking', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'checkbox',
|
||||
'choices' => array(
|
||||
array(
|
||||
'label' => esc_html__( 'Enable pagination tracking', 'gravityformsgoogleanalytics' ),
|
||||
'name' => 'google_analytics_pagination',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'title' => esc_html__( 'Event Parameters', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => $this->get_ga4_event_fields( $form, 'pagination' ),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'google_analytics_pagination',
|
||||
'values' => array( '1' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
array(
|
||||
'title' => esc_html__( 'Form Settings', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'label' => esc_html__( 'Pagination Tracking', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'html',
|
||||
'html' => '<p>' . esc_html__( 'Add a Page field to your form to begin tracking pagination events.', 'gravityformsgoogleanalytics' ) . '</p>',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+768
@@ -0,0 +1,768 @@
|
||||
<?php
|
||||
/**
|
||||
* Object responsible for organizing and constructing the plugin settings page.
|
||||
*/
|
||||
|
||||
namespace Gravity_Forms\Gravity_Forms_Google_Analytics\Settings;
|
||||
|
||||
defined( 'ABSPATH' ) || die();
|
||||
|
||||
use Gravity_Forms\Gravity_Forms_Google_Analytics\GF_Google_Analytics;
|
||||
use GFCommon;
|
||||
|
||||
class Plugin_Settings {
|
||||
/**
|
||||
* Add-on instance.
|
||||
*
|
||||
* @var GF_Google_Analytics
|
||||
*/
|
||||
private $addon;
|
||||
/**
|
||||
* Defines the capability needed to access the Add-On form settings page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access protected
|
||||
* @var string $_capabilities_form_settings The capability needed to access the Add-On form settings page.
|
||||
*/
|
||||
protected $_capabilities_form_settings = 'gravityforms_googleanalytics';
|
||||
|
||||
/**
|
||||
* Stores the auth_payload returned after OAuth has been completed.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $auth_payload;
|
||||
|
||||
/**
|
||||
* Plugin_Settings constructor.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param GF_Google_Analytics $addon GF_Google_Analytics instance.
|
||||
*/
|
||||
public function __construct( $addon ) {
|
||||
$this->addon = $addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin settings fields.
|
||||
*
|
||||
* @since 1.0
|
||||
* @see GF_Google_Analytics::plugin_settings_fields()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_fields() {
|
||||
|
||||
if ( $this->is_connected() ) {
|
||||
return array(
|
||||
$this->get_connection_display(),
|
||||
$this->get_advanced_fields(),
|
||||
);
|
||||
}
|
||||
|
||||
if ( $this->is_manual_configuration() ) {
|
||||
return array( $this->manual_connection_settings() );
|
||||
}
|
||||
|
||||
if ( $this->is_unconfigured_connection() ) {
|
||||
return $this->show_settings_for_action( rgget( 'action' ) );
|
||||
}
|
||||
|
||||
return $this->get_connection_mode_fields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the settings updated notice
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function maybe_display_settings_updated() {
|
||||
if ( rgget( 'updated' ) ) {
|
||||
printf(
|
||||
'<div class="alert gforms_note_success" role="alert">%s</div>',
|
||||
esc_html__( 'Settings Updated.', 'gravityformsgoogleanalytics' )
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determine if this is connection mode selected was manual configuration.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_manual_configuration() {
|
||||
return $this->addon->get_options( 'is_manual' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the add-on can initialize the API and that an action exists.
|
||||
*
|
||||
* Determines if the user has been redirected from the OAuth flow with a token and an action
|
||||
* but the settings have not been saved yet.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_unconfigured_connection() {
|
||||
return empty( $this->addon->get_options( 'mode' ) ) && rgget( 'action' ) && $this->addon->initialize_api();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the addon can initialize the API and that settings were saved.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_connected() {
|
||||
return ! empty( $this->addon->get_options( 'mode' ) ) && $this->addon->initialize_api();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the settings fields for a certain action.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param string $action The action extracted from the query args to show the settings for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function show_settings_for_action( $action ) {
|
||||
if ( 'gaselect' === $action ) {
|
||||
return $this->google_analytics_connection_settings();
|
||||
}
|
||||
if ( 'gtmselect' === $action ) {
|
||||
return $this->google_tag_manager_settings();
|
||||
}
|
||||
|
||||
return $this->get_connection_mode_fields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection mode fields. These are the fields that let the user choose between the three connection types.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_connection_mode_fields() {
|
||||
|
||||
$card_choices = array(
|
||||
array(
|
||||
'label' => esc_html__( 'Measurement Protocol', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'gmp',
|
||||
'icon' => $this->addon->get_base_url() . '/img/google.svg',
|
||||
'tag' => esc_html__( 'Recommended', 'gravityformsgoogleanalytics' ),
|
||||
'color' => 'orange',
|
||||
'title' => esc_html__( 'Google Measurement Protocol', 'gravityformsgoogleanalytics' ),
|
||||
'description' => esc_html__( 'The Measurement Protocol is a server-to-server connection with Google Analytics. It is the most reliable mechanism for event tracking, but it does not include data such as AdWords, Remarketing, or tracking variables.', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
array(
|
||||
'label' => esc_html__( 'Google Analytics', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'ga',
|
||||
'icon' => $this->addon->get_base_url() . '/img/analytics.svg',
|
||||
'tag' => esc_html__( 'Flexible', 'gravityformsgoogleanalytics' ),
|
||||
'color' => 'blue-ribbon',
|
||||
'title' => esc_html__( 'Google Analytics', 'gravityformsgoogleanalytics' ),
|
||||
'description' => esc_html__( 'Google Analytics mode will send data such as Source/Medium (e.g., the page leading to a conversion). Additionally, Google Analytics mode will send information about your user such as location, language, browser information, and AdWords/Remarketing information.', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
array(
|
||||
'label' => esc_html__( 'Tag Manager', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'gtm',
|
||||
'icon' => $this->addon->get_base_url() . '/img/gtm.svg',
|
||||
'tag' => esc_html__( 'Advanced', 'gravityformsgoogleanalytics' ),
|
||||
'color' => 'orange',
|
||||
'title' => esc_html__( 'Google Tag Manager', 'gravityformsgoogleanalytics' ),
|
||||
'description' => esc_html__( 'If you need more control after a form has been submitted, such as setting up a remarketing tag, then Google Tag Manager may be the best option.', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->display_manual_connection_mode() ) {
|
||||
$card_choices[] = array(
|
||||
'label' => esc_html__( 'Manual Configuration', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'manual',
|
||||
'icon' => $this->addon->get_base_url() . '/img/manual.svg',
|
||||
'tag' => esc_html__( 'Advanced', 'gravityformsgoogleanalytics' ),
|
||||
'color' => 'orange',
|
||||
'title' => esc_html__( 'Manual Configuration', 'gravityformsgoogleanalytics' ),
|
||||
'description' => esc_html__( 'Use this option if you are an advanced user and would like to manually enter your Google Analytics information.', 'gravityformsgoogleanalytics' ),
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
array(
|
||||
'title' => esc_html__( 'Select Tracking Connection Type', 'gravityformsgoogleanalytics' ),
|
||||
'description' => esc_html__( 'Using the Google Analytics Platform you can easily add your Google Analytics tracking code to any of your Gravity Forms, in order to track visitor behavior and demographics. We offer three ways to connect to the service.', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'nonce',
|
||||
'type' => 'nonce_connect',
|
||||
'readonly' => true,
|
||||
),
|
||||
array(
|
||||
'name' => 'action',
|
||||
'type' => 'hidden',
|
||||
'readonly' => true,
|
||||
'value' => 'google_analytics_setup',
|
||||
'id' => 'google-analytics-setup',
|
||||
),
|
||||
array(
|
||||
'type' => 'save',
|
||||
'value' => esc_html__( 'Continue →', 'gravityformsgoogleanalytics' ),
|
||||
'id' => 'ga-connect',
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
array(
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'mode',
|
||||
'type' => 'card',
|
||||
'choices' => $card_choices,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the manual connection mode options should be displayed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return bool Returns true if the manual connection mode options should be displayed. Returns false otherwise.
|
||||
*/
|
||||
private function display_manual_connection_mode() {
|
||||
$version_info = GFCommon::get_version_info();
|
||||
return apply_filters( 'gform_googleanalytics_allow_manual_configuration', $version_info['is_valid_key'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection specific settings for Google Analytics.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function google_analytics_connection_settings() {
|
||||
return array(
|
||||
array(
|
||||
'id' => 'google-analytics-settings',
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'gafields',
|
||||
'type' => 'ga_select_account',
|
||||
'label' => esc_html__( 'Select a Google Analytics Account', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
array(
|
||||
'name' => 'nonce',
|
||||
'type' => 'nonce_connect',
|
||||
),
|
||||
array(
|
||||
'name' => 'action',
|
||||
'type' => 'ga_action',
|
||||
),
|
||||
array(
|
||||
'name' => 'save',
|
||||
'type' => 'save',
|
||||
'value' => __( 'Complete Setup', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the connection specific settings for Google Tag Manager.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function google_tag_manager_settings() {
|
||||
return array(
|
||||
array(
|
||||
'id' => 'google-analytics-settings',
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'gtmfields',
|
||||
'type' => 'gtm_select',
|
||||
'label' => esc_html__( 'Select a Google Tag Manager Account', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
array(
|
||||
'name' => 'nonce',
|
||||
'type' => 'nonce_connect',
|
||||
'readonly' => true,
|
||||
),
|
||||
array(
|
||||
'name' => 'action',
|
||||
'type' => 'gtm_action',
|
||||
),
|
||||
array(
|
||||
'name' => 'save',
|
||||
'type' => 'save',
|
||||
'value' => __( 'Complete Setup', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the manual connection settings.
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function manual_connection_settings() {
|
||||
$options = $this->addon->get_options();
|
||||
|
||||
return array(
|
||||
'id' => 'google-analytics-settings',
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'connection_mode',
|
||||
'type' => 'connection_method',
|
||||
'label' => esc_html__( 'Connection Mode', 'gravityformsgoogleanalytics' ),
|
||||
),
|
||||
array(
|
||||
'name' => 'ga_connection_type',
|
||||
'type' => 'select',
|
||||
'label' => esc_html__( 'Connection Type', 'gravityformsgoogleanalytics' ),
|
||||
'value' => rgar( $options, 'mode' ),
|
||||
'choices' => array(
|
||||
array(
|
||||
'label' => esc_html__( 'Select a connection type', 'gravityformsgoogleanalytics' ),
|
||||
'value' => '',
|
||||
),
|
||||
array(
|
||||
'label' => esc_html__( 'Google Analytics', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'ga',
|
||||
),
|
||||
array(
|
||||
'label' => esc_html__( 'Measurement Protocol', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'gmp',
|
||||
),
|
||||
array(
|
||||
'label' => esc_html__( 'Tag Manager', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'gtm',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'ga_measurement_id',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Analytics Measurement ID', 'gravityformsgoogleanalytics' ),
|
||||
'value' => rgars( $options, 'ga4_account/measurement_id' ),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'ga', 'gmp' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'description' => sprintf(
|
||||
// Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
__( 'Please enter the measurement ID (format: G-XXXXXX). %sLearn more about finding your measurement ID%s.', 'gravityformsgoogleanalytics' ),
|
||||
'<a href="https://docs.gravityforms.com/google-analytics-add-on-setup/#h-measurement-protocol" target="_blank">',
|
||||
'</a>'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'ga',
|
||||
'horizontal' => false,
|
||||
'label' => esc_html__( 'Google Analytics Script', 'gravityformsgoogleanalytics' ),
|
||||
'default_value' => 'off',
|
||||
'choices' => array(
|
||||
array(
|
||||
'name' => 'ga_off',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Don\'t Output Google Analytics Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you already have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'I already have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'off',
|
||||
),
|
||||
array(
|
||||
'name' => 'ga_on',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Output Google Analytics Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you would like to have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Output the Google Analytics Script.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'on',
|
||||
),
|
||||
),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'ga' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'ua_tracker',
|
||||
'tooltip' => '<strong>' . esc_html__( 'UA Tracker Name', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Enter the Tracker Name you would like to send events from if you are using a custom Tracker for Google Analytics', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'UA Tracker Name', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'text',
|
||||
'class' => 'small',
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'ga' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'gmp_api_secret',
|
||||
'type' => 'text',
|
||||
'input_type' => 'password',
|
||||
'label' => esc_html__( 'Measurement Protocol API Secret', 'gravityformsgoogleanalytics' ),
|
||||
'value' => rgars( $options, 'ga4_account/gmp_api_secret' ),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'gmp' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'description' => sprintf(
|
||||
// Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
__( 'Please enter your API secret. %1$sLearn more about finding your API secret%2$s.', 'gravityformsgoogleanalytics' ),
|
||||
'<a href="https://docs.gravityforms.com/google-analytics-add-on-setup/#h-measurement-protocol" target="_blank">',
|
||||
'</a>'
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'gtm_container_id',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Tag Manager Container ID', 'gravityformsgoogleanalytics' ),
|
||||
'value' => rgars( $options, 'ga4_account/gtm_container_id' ),
|
||||
'description' => sprintf(
|
||||
// Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
__( 'Please enter the container ID (format: GTM-XXXXXX). %1$sLearn more about finding your container ID%2$s.', 'gravityformsgoogleanalytics' ),
|
||||
'<a href="https://docs.gravityforms.com/google-analytics-add-on-setup/#h-tag-manager" target="_blank">',
|
||||
'</a>'
|
||||
),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'gtm' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'gtm_workspace_id',
|
||||
'type' => 'text',
|
||||
'label' => esc_html__( 'Tag Manager Workspace ID', 'gravityformsgoogleanalytics' ),
|
||||
'value' => rgars( $options, 'ga4_account/gtm_workspace_id' ),
|
||||
'description' => sprintf(
|
||||
// Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
__( 'Please enter the workspace name Id. %1$sLearn more about finding your Workspaces%2$s.', 'gravityformsgoogleanalytics' ),
|
||||
'<a href="https://docs.gravityforms.com/google-analytics-add-on-setup/#h-tag-manager" target="_blank">',
|
||||
'</a>'
|
||||
),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'gtm' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'install_gtm',
|
||||
'horizontal' => false,
|
||||
'label' => esc_html__( 'Google Tag Manager Script', 'gravityformsgoogleanalytics' ),
|
||||
'default_value' => 'off',
|
||||
'choices' => array(
|
||||
array(
|
||||
'name' => 'gtm_off',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Don\'t Output the Google Tag Manager Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you already have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'I already have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'off',
|
||||
),
|
||||
array(
|
||||
'name' => 'gtm_on',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Output Google Tag Manager Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you would like to have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Output the Google Tag Manager Script.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'on',
|
||||
),
|
||||
),
|
||||
'dependency' => array(
|
||||
'live' => true,
|
||||
'fields' => array(
|
||||
array(
|
||||
'field' => 'ga_connection_type',
|
||||
'values' => array( 'gtm' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'manual_action',
|
||||
'type' => 'manual_action',
|
||||
),
|
||||
array(
|
||||
'name' => 'nonce',
|
||||
'type' => 'nonce_connect',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the advanced settings fields.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_advanced_fields() {
|
||||
$options = $this->addon->get_options();
|
||||
$mode = $options['mode'];
|
||||
|
||||
if ( $mode === 'gtm' ) {
|
||||
return array(
|
||||
'title' => esc_html__( 'Advanced', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'install_gtm',
|
||||
'horizontal' => false,
|
||||
'label' => esc_html__( 'Google Tag Manager Script', 'gravityformsgoogleanalytics' ),
|
||||
'default_value' => 'off',
|
||||
'choices' => array(
|
||||
array(
|
||||
'name' => 'gtm_off',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Don\'t Output the Google Tag Manager Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you already have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'I already have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'off',
|
||||
),
|
||||
array(
|
||||
'name' => 'gtm_on',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Output Google Tag Manager Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you would like to have Google Tag Manager installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Output the Google Tag Manager Script.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'on',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} elseif ( $mode === 'ga' ) {
|
||||
return array(
|
||||
'title' => esc_html__( 'Advanced', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'ga',
|
||||
'horizontal' => false,
|
||||
'label' => esc_html__( 'Google Analytics Script', 'gravityformsgoogleanalytics' ),
|
||||
'default_value' => 'off',
|
||||
'choices' => array(
|
||||
array(
|
||||
'name' => 'ga_off',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Don\'t Output Google Analytics Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you already have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'I already have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'off',
|
||||
),
|
||||
array(
|
||||
'name' => 'ga_on',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Output Google Analytics Script', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Choose this option if you would like to have Google Analytics installed.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Output the Google Analytics Script.', 'gravityformsgoogleanalytics' ),
|
||||
'value' => 'on',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'name' => 'ua_tracker',
|
||||
'tooltip' => '<strong>' . esc_html__( 'UA Tracker Name', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Enter the Tracker Name you would like to send events from if you are using a custom Tracker for Google Analytics', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'UA Tracker Name', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'text',
|
||||
'class' => 'small',
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'fields' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show information about the current connection.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_connection_display() {
|
||||
$options = $this->addon->get_options();
|
||||
$mode = $options['mode'];
|
||||
return array(
|
||||
'title' => esc_html__( 'Google Analytics Settings', 'gravityformsgoogleanalytics' ),
|
||||
'fields' => array(
|
||||
array(
|
||||
'name' => 'connection_method',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Connection Type', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'Displays the current connection type. To change this, disconnect and reconnect using another type.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Connection Type', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'connection_method',
|
||||
),
|
||||
array(
|
||||
'name' => 'analytics_account',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Analytics Account', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'The Google Analytics Data Stream which will receive the conversion events.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Analytics Account', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'analytics_account',
|
||||
'hidden' => $mode == 'gtm',
|
||||
),
|
||||
array(
|
||||
'name' => 'measurement_id',
|
||||
'tooltip' => '<strong>' . esc_html__( 'Analytics Measurement ID', 'gravityformsgoogleanalytics' ) . '</strong>' . esc_html__( 'The measurement ID identifies the Google Analytics Data Stream which will receive the conversion events.', 'gravityformsgoogleanalytics' ),
|
||||
'label' => esc_html__( 'Analytics Measurement ID', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'measurement_id',
|
||||
'hidden' => $mode == 'gtm',
|
||||
),
|
||||
array(
|
||||
'name' => 'tag_manager_account',
|
||||
'label' => esc_html__( 'Tag Manager Account', 'gravityformsgoogleanalytics' ),
|
||||
'type' => 'tag_manager_account',
|
||||
'hidden' => $mode != 'gtm',
|
||||
),
|
||||
array(
|
||||
'type' => 'nonce_connect',
|
||||
'name' => 'nonce',
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store auth tokens when we get auth payload from Google Analytics.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
public function maybe_update_auth_tokens() {
|
||||
|
||||
$payload = $this->find_oauth_payload();
|
||||
|
||||
if ( ! $payload ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( rgar( $payload, 'auth_error' ) ) {
|
||||
GFCommon::add_message( esc_html__( 'An error occured while connecting to the API.', 'gravityformsgoogleanalytics' ) );
|
||||
$this->addon->log_error( $payload['auth_error'] );
|
||||
return;
|
||||
}
|
||||
|
||||
$auth_payload = $this->get_decoded_auth_payload( $payload );
|
||||
$this->auth_payload = $auth_payload;
|
||||
|
||||
// If access token is provided, save it.
|
||||
if ( rgar( $auth_payload, 'access_token' ) ) {
|
||||
// Get the authentication token.
|
||||
$settings = array();
|
||||
$settings['token'] = rgar( $auth_payload, 'access_token' );
|
||||
$settings['refresh'] = rgar( $auth_payload, 'refresh_token' );
|
||||
$settings['date_created'] = time();
|
||||
$this->addon->update_options( $settings, 'auth_token' );
|
||||
GFCommon::add_message( esc_html__( 'Google Analytics settings have been updated.', 'gravityformsgoogleanalytics' ) );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determine if we have a valid nonce and capabilities.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $container The array that contains the nonce, defaults to $_POST.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_valid_action( $container = array() ) {
|
||||
$container = empty( $container ) ? $_POST : $container;
|
||||
return wp_verify_nonce( rgar( $container, 'state' ), 'gravityforms_googleanalytics_google_connect' ) && $this->addon->current_user_can_any( $this->_capabilities_form_settings );
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes the auth_payload returned form Gravity API.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $payload The payload received from Gravity API.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_decoded_auth_payload( $payload ) {
|
||||
$auth_payload_string = rgar( $payload, 'auth_payload' );
|
||||
return empty( $auth_payload_string ) ? array() : json_decode( $auth_payload_string, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorization payload data.
|
||||
*
|
||||
* Returns the auth POST request if it's present, otherwise attempts to return a recent transient cache.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function find_oauth_payload() {
|
||||
$payload = array_filter(
|
||||
array(
|
||||
'auth_payload' => rgpost( 'auth_payload' ),
|
||||
'auth_error' => rgpost( 'auth_error' ),
|
||||
'state' => rgpost( 'state' ),
|
||||
)
|
||||
);
|
||||
|
||||
if (
|
||||
(
|
||||
$this->is_valid_action( $this->get_decoded_auth_payload( $payload ) )
|
||||
&& count( $payload ) === 2
|
||||
)
|
||||
|| isset( $payload['auth_error'] )
|
||||
) {
|
||||
return $payload;
|
||||
}
|
||||
|
||||
$payload = get_transient( 'gravityapi_response_' . $this->addon->get_slug() );
|
||||
if ( rgar( $payload, 'state' ) !== get_transient( 'gravityapi_request_' . $this->addon->get_slug() ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
delete_transient( 'gravityapi_response_' . $this->addon->get_slug() );
|
||||
return is_array( $payload ) ? $payload : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the auth_payload.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_auth_payload() {
|
||||
return $this->auth_payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
( function ( GF_Google_Analytics_Admin, $ ) {
|
||||
function display_error( message ) {
|
||||
$( '.gforms_note_error' ).remove();
|
||||
$( '#gform-page-loader-mask' ).hide();
|
||||
$( '#gform-settings' ).before( '<div class="alert gforms_note_error" role="alert">' + message + '</div>' );
|
||||
$( '.alert' ).get(0).scrollIntoView();
|
||||
}
|
||||
function hide_error() {
|
||||
$( '.gforms_note_error' ).remove();
|
||||
}
|
||||
|
||||
jQuery( document ).ready( function() {
|
||||
// Main form wrapper.
|
||||
let $form = $( '#gform-settings' );
|
||||
|
||||
// Handle disconnects from the admin.
|
||||
let $disconnect = $( '.gfga-disconnect' );
|
||||
if ( $disconnect.length > 0 ) {
|
||||
$disconnect.on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
$disconnect.html( google_analytics_admin_strings.disconnect );
|
||||
|
||||
var url_params = wpAjax.unserialize( e.target.href );
|
||||
var nonce_value = url_params.nonce;
|
||||
|
||||
// Perform Ajax request.
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'disconnect_account',
|
||||
nonce: nonce_value,
|
||||
},
|
||||
function( response ) {
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
// Disable submit button and only reenable if required fields are filled out. Necessary to work with new loader.
|
||||
let $action = $form.find( 'input[name="gfgaaction"]');
|
||||
if ( $action.length !== 0 && $action.val() !== 'manual' ) {
|
||||
let $submit_button = $form.find( ':submit' );
|
||||
$submit_button.prop( 'disabled', true );
|
||||
}
|
||||
$( '#gform-settings-section-google-analytics-settings' ).on( 'change', ( 'input, select' ), function( event ) {
|
||||
let property = $form.find( 'select[name="gaproperty"]' ).find(':selected').val();
|
||||
let measurement_id = $( '#ga-data-streams select :selected' ).val();
|
||||
|
||||
let gtm_container = $form.find( 'select[name="gtmproperty"]' ).find( ':selected' ).val();
|
||||
if ( ! gtm_container ) {
|
||||
gtm_container = $form.find( '#container' ).val();
|
||||
}
|
||||
let workspace = $form.find( 'select[name="gaworkspace"]' ).val();
|
||||
if ( ! workspace ) {
|
||||
workspace = $form.find( '#workspace' ).val();
|
||||
}
|
||||
|
||||
let $submit_button = $form.find( ':submit' );
|
||||
if ( 'ga' === $action.val() ) {
|
||||
if ( property && measurement_id ) {
|
||||
$submit_button.prop( 'disabled', false );
|
||||
} else {
|
||||
$submit_button.prop( 'disabled', true );
|
||||
}
|
||||
}
|
||||
if ( 'gtm' === $action.val() ) {
|
||||
if ( gtm_container && workspace ) {
|
||||
$submit_button.prop( 'disabled', false );
|
||||
} else {
|
||||
$submit_button.prop( 'disabled', true );
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Handle form submission on connect screen
|
||||
$form.on( 'submit', function( e ) {
|
||||
|
||||
// Hide error message if there is one being displayed
|
||||
hide_error();
|
||||
|
||||
// Determining if we're just connecting for the first time.
|
||||
if ( $form.find( 'input[value="google_analytics_setup"]' ).length === 1 ) {
|
||||
// is_postback
|
||||
e.preventDefault();
|
||||
|
||||
// Set l18n.
|
||||
var $save_button = $form.find( '#gform-settings-save' );
|
||||
var $mode = $form.find( '[name="_gform_setting_mode"]:checked').val();
|
||||
|
||||
// Validate that a connection type was selected.
|
||||
if ( ! $mode ) {
|
||||
display_error( google_analytics_admin_strings.mode_required );
|
||||
return;
|
||||
}
|
||||
|
||||
$save_button.prop( 'value', google_analytics_admin_strings.redirect ).prop( 'disabled', 'disabled' );
|
||||
|
||||
// Get nonce.
|
||||
var nonce_value = $form.find( 'input[name="gfganonce"]').val();
|
||||
|
||||
// Perform Ajax request.
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'redirect_to_api',
|
||||
nonce: nonce_value,
|
||||
mode: $mode,
|
||||
},
|
||||
function( response ) {
|
||||
if ( ! response.data.errors ) {
|
||||
window.location.href = response.data.redirect;
|
||||
}
|
||||
},
|
||||
'json'
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine if we're executing in the correct form
|
||||
let $action = $form.find( 'input[name="gfgaaction"]');
|
||||
if( $action.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'ga' === $action.val() ) {
|
||||
e.preventDefault();
|
||||
|
||||
// Getting selected items from the account/property and data stream drop downs.
|
||||
let $selected_property = $form.find( 'select[name="gaproperty"]' ).find( ':selected' );
|
||||
let $selected_data_stream = $form.find( '#ga-data-streams select :selected' )
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'save_google_analytics_data',
|
||||
account_id: $selected_property.data( 'account-id' ),
|
||||
account_name: $selected_property.data('account-name'),
|
||||
property_id: $selected_property.val(),
|
||||
property_name: $selected_property.data('property-name'),
|
||||
measurement_id: $selected_data_stream.val(),
|
||||
data_stream_name: $selected_data_stream.data( 'data-stream-name' ),
|
||||
data_stream_id: $selected_data_stream.data( 'data-stream-id' ),
|
||||
nonce: $form.find( 'input[name="gfganonce"]' ).val(),
|
||||
token: $form.find('input[name="gfga_token"]' ).val(),
|
||||
refresh: $form.find('input[name="gfga_refresh"]' ).val(),
|
||||
},
|
||||
function( response ) {
|
||||
if ( response.success ) {
|
||||
window.location.href = response['data'];
|
||||
} else {
|
||||
display_error( response.data[0].message );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if ( 'gtm' === $action.val() ) {
|
||||
// We're in Google Tag Manager mode
|
||||
e.preventDefault();
|
||||
|
||||
// Get Google Analytics data
|
||||
let $selected_property = $form.find( 'select[name="gaproperty"]' ).find( ':selected' );
|
||||
let $selected_data_stream = $form.find( '#ga-data-streams select :selected' )
|
||||
|
||||
// Get GTM Data
|
||||
let $selected_gtm_account = $form.find( 'select[name="gtmproperty"] :selected' );
|
||||
let $selected_gtm_container = $form.find( 'select[name="gacontainer"] :selected' );
|
||||
let $gtm_workspace = $form.find( 'select[name="gaworkspace"] :selected' );
|
||||
let $gtm_auto_create = $form.find( 'input[name="_gform_setting_gtm_auto_create"]' );
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action : 'save_google_tag_manager_data',
|
||||
account_id : $selected_property.data( 'account-id' ),
|
||||
account_name : $selected_property.data( 'account-name' ),
|
||||
property_id : $selected_property.val(),
|
||||
property_name : $selected_property.data( 'property-name' ),
|
||||
measurement_id : $selected_data_stream.val(),
|
||||
data_stream_name : $selected_data_stream.data( 'data-stream-name' ),
|
||||
gtm_account_id : $selected_gtm_account.data( 'account-id' ),
|
||||
gtm_account_name : $selected_gtm_account.val(),
|
||||
gtm_api_path : $selected_gtm_container.data( 'path' ),
|
||||
gtm_container : $selected_gtm_container.val(),
|
||||
gtm_auto_create : $gtm_auto_create.val(),
|
||||
gtm_workspace_id : $gtm_workspace.val(),
|
||||
gtm_workspace_name : $gtm_workspace.text(),
|
||||
nonce : $form.find( 'input[name="gfganonce"]' ).val(),
|
||||
token : $form.find( 'input[name="gfga_token"]' ).val(),
|
||||
refresh : $form.find( 'input[name="gfga_refresh"]' ).val(),
|
||||
},
|
||||
function( response ) {
|
||||
if ( false === response.success ) {
|
||||
display_error( response.data[0].message );
|
||||
} else {
|
||||
window.location.href = response.data;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
if ( 'manual' === $action.val() ) {
|
||||
// We're in manual configuration mode
|
||||
e.preventDefault();
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action : 'save_manual_configuration_data',
|
||||
mode : $form.find( '#ga_connection_type' ).val(),
|
||||
measurement_id : $form.find( '#ga_measurement_id' ).val(),
|
||||
gmp_api_secret : $form.find( '#gmp_api_secret' ).val(),
|
||||
gtm_container : $form.find( '#gtm_container_id' ).val(),
|
||||
gtm_workspace_id : $form.find( '#gtm_workspace_id' ).val(),
|
||||
nonce : $form.find( 'input[name="gfganonce"]' ).val(),
|
||||
ga : $form.find( 'input[name="_gform_setting_ga"]:checked' ).val(),
|
||||
install_gtm : $form.find('input[name="_gform_setting_install_gtm"]:checked').val(),
|
||||
ua_tracker : $form.find('input[name="_gform_setting_ua_tracker"]').val(),
|
||||
},
|
||||
function( response ) {
|
||||
if ( false === response.success ) {
|
||||
display_error( response.data[0].message );
|
||||
} else {
|
||||
window.location.href = response.data;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
// Get data streams for selected Analytics account/property.
|
||||
$( '#gaproperty' ).on( 'change', function( e ) {
|
||||
|
||||
// Hide error message if there is one being displayed
|
||||
hide_error();
|
||||
|
||||
let $option = $( this ).find( ':selected' );
|
||||
let nonce = $( 'body' ).find( 'input[name="gfganonce"]' ).val();
|
||||
let token = $form.find('input[name="gfga_token"]' ).val();
|
||||
|
||||
$( '#ga-data-streams' ).html( '<br /><img src="' + google_analytics_admin_strings.spinner + '" />' );
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'get_ga4_data_streams',
|
||||
account: $option.data( 'account-id' ),
|
||||
property: $option.val(),
|
||||
nonce: nonce,
|
||||
token: token,
|
||||
},
|
||||
function( response ) {
|
||||
if ( response.success ) {
|
||||
$( '#ga-data-streams' ).html( response['data'] );
|
||||
} else {
|
||||
$( '#ga-data-streams' ).html( '' );
|
||||
display_error( response.data[0].message );
|
||||
}
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
// Get containers for selected GTM account.
|
||||
$( '#gtmproperty' ).on( 'change', function( e ) {
|
||||
|
||||
// Hide error message if there is one being displayed
|
||||
hide_error();
|
||||
|
||||
const $option = $( this ).find( ':selected' );
|
||||
const accountId = $option.data( 'accountId' );
|
||||
const path = $option.data( 'path' );
|
||||
const token = $option.data( 'token' );
|
||||
const nonce = $( 'body' ).find( 'input[name="gfganonce"]' ).val();
|
||||
$( '#gtm-containers' ).html( '<br /><img src="' + google_analytics_admin_strings.spinner + '" />' );
|
||||
$( '#gtm-workspaces' ).html( '' );
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'get_gtm_containers',
|
||||
accountId: accountId,
|
||||
path: path,
|
||||
nonce: nonce,
|
||||
token: token,
|
||||
},
|
||||
function( response ) {
|
||||
if( response.success ) {
|
||||
$( '#gtm-containers' ).html( response.body );
|
||||
} else {
|
||||
display_error( response.data[0].message );
|
||||
$( '#gtm-containers' ).html( '' );
|
||||
}
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
// Get views for selected UA account.
|
||||
$( document ).on( 'change', '#gacontainer', function( e ) {
|
||||
|
||||
// Hide error message if there is one being displayed
|
||||
hide_error();
|
||||
|
||||
const $option = $( this ).find( ':selected' );
|
||||
const path = $option.data( 'path' );
|
||||
const token = $option.data( 'token' );
|
||||
const nonce = $( 'body' ).find( 'input[name="gfganonce"]' ).val();
|
||||
$( '#gtm-workspaces' ).html( '<br /><img src="' + google_analytics_admin_strings.spinner + '" />' );
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'get_gtm_workspaces',
|
||||
path: path,
|
||||
nonce: nonce,
|
||||
token: token,
|
||||
},
|
||||
function( response ) {
|
||||
if( response.success ) {
|
||||
$( '#gtm-workspaces' ).html( response.body );
|
||||
} else {
|
||||
display_error( response.data[0].message );
|
||||
$( '#gform_setting_workspace' ).show();
|
||||
$( '#gtm-workspaces' ).html( '' );
|
||||
}
|
||||
}
|
||||
);
|
||||
} );
|
||||
} );
|
||||
}( window.GF_Google_Analytics_Admin = window.GF_Google_Analytics_Admin || {}, jQuery ) );
|
||||
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,289 @@
|
||||
( function () {
|
||||
|
||||
/**
|
||||
* Send events to Google Analytics. Use Ajax call so no duplicate entries are recorded.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {number} entryId The entry ID associated with this submission.
|
||||
* @param {number} feedId The feed ID associated with this event.
|
||||
* @param {array} parameters Event parameters to send to Google Analytics.
|
||||
* @param {string} eventName Event name to be sent to Google Analytics.
|
||||
*/
|
||||
this.send_unique_to_ga = async function ( entryId, feedId, parameters, eventName ) {
|
||||
let has_sent = await this.has_sent_feed( entryId, feedId );
|
||||
if ( ! has_sent ) {
|
||||
this.send_to_ga( parameters, eventName );
|
||||
this.mark_feed_as_sent( entryId, feedId );
|
||||
}
|
||||
this.maybe_trigger_feeds_sent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send events to Google Analytics. Use ajax call so no duplicate entries are recorded.
|
||||
*
|
||||
* @since 1.0.0
|
||||
|
||||
* @param {array} parameters Event parameters to send to Google Analytics.
|
||||
* @param {string} eventName Event name to be sent to Google Analytics.
|
||||
*/
|
||||
this.send_to_ga = function( parameters, eventName ) {
|
||||
|
||||
const eventTracker = gforms_google_analytics_frontend_strings.ua_tracker;
|
||||
|
||||
// Check for gtab implementation
|
||||
if ( typeof window.parent.gtag != 'undefined' ) {
|
||||
window.parent.gtag( 'event', eventName, parameters );
|
||||
} else {
|
||||
// Check for GA from Monster Insights Plugin
|
||||
if ( typeof window.parent.ga == 'undefined' ) {
|
||||
if ( typeof window.parent.__gaTracker != 'undefined' ) {
|
||||
window.parent.ga = window.parent.__gaTracker;
|
||||
}
|
||||
}
|
||||
if ( typeof window.parent.ga != 'undefined' ) {
|
||||
|
||||
let ga_send = 'send';
|
||||
// Try to get original UA code from third-party plugins or tag manager
|
||||
if ( eventTracker.length > 0 ) {
|
||||
ga_send = eventTracker + '.' + ga_send;
|
||||
}
|
||||
|
||||
// Use that tracker
|
||||
window.parent.ga( ga_send, eventName, parameters );
|
||||
} else {
|
||||
console.error( 'Google Tag Manger script is not active. You may need to enable "Output the Google Analytics Script" setting on the Forms -> Settings -> Google Analytics page');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Logging if enabled.
|
||||
const eventData = { 'type': 'ga', 'eventName' : eventName, 'parameters' : parameters };
|
||||
this.consoleLog('Google Analytics event sent. Event data: ');
|
||||
this.consoleLog( JSON.stringify( eventData, null, 2 ) );
|
||||
|
||||
// Triggering event_sent event.
|
||||
this.trigger_event( 'googleanalytics/event_sent', eventData );
|
||||
jQuery.post(
|
||||
gforms_google_analytics_frontend_strings.ajaxurl,
|
||||
{
|
||||
action: 'gf_ga_log_event_sent',
|
||||
parameters: parameters,
|
||||
eventName: eventName,
|
||||
connection: 'ga',
|
||||
nonce: gforms_google_analytics_frontend_strings.logging_nonce,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send events to Google Tag Manager.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {number} entryId The entry ID associated with this submission.
|
||||
* @param {number} feedId The feed ID associated with this event.
|
||||
* @param {array} parameters Event parameters to send to Google Analytics.
|
||||
* @param {string} triggerName Event type to be sent to Google Analytics.
|
||||
*/
|
||||
this.send_unique_to_gtm = async function( entryId, feedId, parameters, triggerName) {
|
||||
|
||||
let has_sent = await this.has_sent_feed( entryId, feedId );
|
||||
if ( ! has_sent ) {
|
||||
this.send_to_gtm( parameters, triggerName );
|
||||
this.mark_feed_as_sent( entryId, feedId );
|
||||
} else {
|
||||
this.consoleLog( 'Event has already been sent. Aborting... Entry id: ' + entryId + '. Feed Id: ' + feedId );
|
||||
}
|
||||
this.maybe_trigger_feeds_sent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send events to Google Tag Manager.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param {array} parameters Event parameters to send to Google Analytics.
|
||||
* @param {string} triggerName Event name to be sent to Google Tag Manger.
|
||||
*/
|
||||
this.send_to_gtm = function( parameters, triggerName) {
|
||||
if ( typeof ( window.parent.dataLayer ) == 'undefined' ) {
|
||||
console.error( 'Google Tag Manger script is not active. You may need to enable "Output the Google Tag Manager Script" setting on the Forms -> Settings -> Google Analytics page' );
|
||||
return;
|
||||
}
|
||||
|
||||
parameters['event'] = triggerName;
|
||||
window.parent.dataLayer.push( parameters );
|
||||
|
||||
// Logging if enabled.
|
||||
const eventData = { 'type': 'gtm', 'triggerName' : triggerName, 'parameters' : parameters };
|
||||
this.consoleLog('Google Analytics event sent. Event data: ');
|
||||
this.consoleLog( JSON.stringify( eventData, null, 2 ) );
|
||||
|
||||
// Triggering event_sent event.
|
||||
this.trigger_event( 'googleanalytics/event_sent', eventData );
|
||||
jQuery.post(
|
||||
gforms_google_analytics_frontend_strings.ajaxurl,
|
||||
{
|
||||
action: 'gf_ga_log_event_sent',
|
||||
parameters: parameters,
|
||||
triggerName: triggerName,
|
||||
connection: 'gtm',
|
||||
nonce: gforms_google_analytics_frontend_strings.logging_nonce,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if event for this entry and feed has already been sent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {number} entryId Current entry id.
|
||||
* @param {number} feedId Current feed id.
|
||||
*
|
||||
* @returns {bool} Returns true if the event for this entry and feed has already been sent. Returns false if not.
|
||||
*/
|
||||
this.has_sent_feed = async function( entryId, feedId ) {
|
||||
let response = await jQuery.post( gforms_google_analytics_frontend_strings.ajaxurl, { action: 'get_entry_meta', entry_id: entryId, feed_id: feedId, nonce: gforms_google_analytics_frontend_strings.nonce }, 'json' );
|
||||
return response.data.event_sent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark an event as sent via AJAX. Part of the system to prevent duplicate events from being sent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {number} entryId Current entry id.
|
||||
* @param {number} feedId Current feed id.
|
||||
*/
|
||||
this.mark_feed_as_sent = function( entryId, feedId ) {
|
||||
jQuery.post( gforms_google_analytics_frontend_strings.ajaxurl, { action: 'save_entry_meta', entry_id: entryId, feed_id: feedId, nonce: gforms_google_analytics_frontend_strings.nonce } );
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the number of feeds that have been sent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
this.feeds_sent = 0;
|
||||
|
||||
/**
|
||||
* Triggers 'googleanalytics/all_events_sent' after the last feed has been sent.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
this.maybe_trigger_feeds_sent = function() {
|
||||
|
||||
this.feeds_sent++;
|
||||
this.consoleLog( 'Google Analytics event successfully sent: ' + this.feeds_sent + ' of ' + window['ga_feed_count'] );
|
||||
if ( this.feeds_sent >= window['ga_feed_count'] ) {
|
||||
|
||||
this.consoleLog( 'All Google Analytics events have been sent.' );
|
||||
|
||||
// All feeds have been sent. Trigger feeds sent event.
|
||||
this.trigger_event( 'googleanalytics/all_events_sent' );
|
||||
window['all_ga_events_sent'] = true;
|
||||
|
||||
// Reset counters.
|
||||
this.feeds_sent = 0;
|
||||
window['ga_feed_count'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a Javascript event.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {string} eventName Name of the event.
|
||||
* @param {*} eventData Data associated with this event.
|
||||
*/
|
||||
this.trigger_event = function( eventName, eventData ) {
|
||||
const event = new CustomEvent( eventName, { detail: eventData } );
|
||||
window.dispatchEvent( event );
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs to the console if logging is enabled in settings page.
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param {*} message The message to be logged.
|
||||
*/
|
||||
this.consoleLog = function( message ) {
|
||||
if ( gforms_google_analytics_frontend_strings.logging_enabled !== '1' ) {
|
||||
return;
|
||||
}
|
||||
console.log( message );
|
||||
}
|
||||
|
||||
this.handle_ajax_feeds = async function( data ) {
|
||||
if ( ! data?.submissionResult?.data?.ajax_feeds ) {
|
||||
return data;
|
||||
}
|
||||
|
||||
for ( const feed of data.submissionResult.data.ajax_feeds ) {
|
||||
|
||||
if ( feed?.mode == 'ga' ) {
|
||||
this.send_unique_to_ga( data.submissionResult.data.entry_id, feed.feed_id, feed.parameters, feed.eventName );
|
||||
}
|
||||
|
||||
if ( feed?.mode == 'gtm' ) {
|
||||
this.send_unique_to_gtm( data.submissionResult.data.entry_id, feed.feed_id, feed.parameters, feed.eventName );
|
||||
}
|
||||
|
||||
window.parent[ 'ga_feed_count' ] = window.parent[ 'ga_feed_count' ] ? window.parent[ 'ga_feed_count' ] + 1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
this.handle_ajax_pagination = function( data ) {
|
||||
if ( ! data?.submissionResult?.data?.ajax_pagination ) {
|
||||
return data;
|
||||
}
|
||||
|
||||
const ajaxPagination = data?.submissionResult?.data?.ajax_pagination
|
||||
|
||||
if ( ajaxPagination?.mode == 'ga' ) {
|
||||
window.parent.GF_Google_Analytics.send_to_ga( ajaxPagination.parameters, ajaxPagination.eventName );
|
||||
}
|
||||
|
||||
if ( ajaxPagination?.mode == 'gtm' ) {
|
||||
window.parent.GF_Google_Analytics.send_to_gtm( ajaxPagination.parameters, ajaxPagination.eventName );
|
||||
}
|
||||
|
||||
this.consoleLog( 'Pagination event has been sent.' );
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes this object.
|
||||
*/
|
||||
this.init = function() {
|
||||
window.GF_Google_Analytics = this;
|
||||
let ajaxFilterRegistered = false;
|
||||
|
||||
// Trigger script loaded event
|
||||
this.trigger_event( 'googleanalytics/script_loaded' );
|
||||
|
||||
document.addEventListener( 'gform/post_render', ( ) => {
|
||||
if ( ajaxFilterRegistered ) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.gform.utils.addFilter( 'gform/ajax/post_ajax_submission', ( data ) => {
|
||||
this.handle_ajax_feeds( data );
|
||||
this.handle_ajax_pagination( data );
|
||||
return data;
|
||||
} );
|
||||
|
||||
ajaxFilterRegistered = true;
|
||||
} );
|
||||
}
|
||||
|
||||
this.init();
|
||||
}() );
|
||||
@@ -0,0 +1 @@
|
||||
!function(){this.send_unique_to_ga=async function(e,t,n,s){await this.has_sent_feed(e,t)||(this.send_to_ga(n,s),this.mark_feed_as_sent(e,t)),this.maybe_trigger_feeds_sent()},this.send_to_ga=function(t,n){var s=gforms_google_analytics_frontend_strings.ua_tracker;if(void 0!==window.parent.gtag)window.parent.gtag("event",n,t);else{if(void 0===window.parent.ga&&void 0!==window.parent.__gaTracker&&(window.parent.ga=window.parent.__gaTracker),void 0===window.parent.ga)return void console.error('Google Tag Manger script is not active. You may need to enable "Output the Google Analytics Script" setting on the Forms -> Settings -> Google Analytics page');{let e="send";0<s.length&&(e=s+"."+e),window.parent.ga(e,n,t)}}s={type:"ga",eventName:n,parameters:t};this.consoleLog("Google Analytics event sent. Event data: "),this.consoleLog(JSON.stringify(s,null,2)),this.trigger_event("googleanalytics/event_sent",s),jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"gf_ga_log_event_sent",parameters:t,eventName:n,connection:"ga",nonce:gforms_google_analytics_frontend_strings.logging_nonce})},this.send_unique_to_gtm=async function(e,t,n,s){await this.has_sent_feed(e,t)?this.consoleLog("Event has already been sent. Aborting... Entry id: "+e+". Feed Id: "+t):(this.send_to_gtm(n,s),this.mark_feed_as_sent(e,t)),this.maybe_trigger_feeds_sent()},this.send_to_gtm=function(e,t){var n;void 0===window.parent.dataLayer?console.error('Google Tag Manger script is not active. You may need to enable "Output the Google Tag Manager Script" setting on the Forms -> Settings -> Google Analytics page'):(e.event=t,window.parent.dataLayer.push(e),n={type:"gtm",triggerName:t,parameters:e},this.consoleLog("Google Analytics event sent. Event data: "),this.consoleLog(JSON.stringify(n,null,2)),this.trigger_event("googleanalytics/event_sent",n),jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"gf_ga_log_event_sent",parameters:e,triggerName:t,connection:"gtm",nonce:gforms_google_analytics_frontend_strings.logging_nonce}))},this.has_sent_feed=async function(e,t){return(await jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"get_entry_meta",entry_id:e,feed_id:t,nonce:gforms_google_analytics_frontend_strings.nonce},"json")).data.event_sent},this.mark_feed_as_sent=function(e,t){jQuery.post(gforms_google_analytics_frontend_strings.ajaxurl,{action:"save_entry_meta",entry_id:e,feed_id:t,nonce:gforms_google_analytics_frontend_strings.nonce})},this.feeds_sent=0,this.maybe_trigger_feeds_sent=function(){this.feeds_sent++,this.consoleLog("Google Analytics event successfully sent: "+this.feeds_sent+" of "+window.ga_feed_count),this.feeds_sent>=window.ga_feed_count&&(this.consoleLog("All Google Analytics events have been sent."),this.trigger_event("googleanalytics/all_events_sent"),window.all_ga_events_sent=!0,this.feeds_sent=0,window.ga_feed_count=0)},this.trigger_event=function(e,t){e=new CustomEvent(e,{detail:t});window.dispatchEvent(e)},this.consoleLog=function(e){"1"===gforms_google_analytics_frontend_strings.logging_enabled&&console.log(e)},this.handle_ajax_feeds=async function(e){if(!e?.submissionResult?.data?.ajax_feeds)return e;for(var t of e.submissionResult.data.ajax_feeds)"ga"==t?.mode&&this.send_unique_to_ga(e.submissionResult.data.entry_id,t.feed_id,t.parameters,t.eventName),"gtm"==t?.mode&&this.send_unique_to_gtm(e.submissionResult.data.entry_id,t.feed_id,t.parameters,t.eventName),window.parent.ga_feed_count=window.parent.ga_feed_count?window.parent.ga_feed_count+1:1},this.handle_ajax_pagination=function(e){var t;return e?.submissionResult?.data?.ajax_pagination&&("ga"==(t=e?.submissionResult?.data?.ajax_pagination)?.mode&&window.parent.GF_Google_Analytics.send_to_ga(t.parameters,t.eventName),"gtm"==t?.mode&&window.parent.GF_Google_Analytics.send_to_gtm(t.parameters,t.eventName),this.consoleLog("Pagination event has been sent.")),e},this.init=function(){window.GF_Google_Analytics=this;let e=!1;this.trigger_event("googleanalytics/script_loaded"),document.addEventListener("gform/post_render",()=>{e||(window.gform.utils.addFilter("gform/ajax/post_ajax_submission",e=>(this.handle_ajax_feeds(e),this.handle_ajax_pagination(e),e)),e=!0)})},this.init()}();
|
||||
+556
@@ -0,0 +1,556 @@
|
||||
# Copyright (C) 2026 Gravity Forms
|
||||
# This file is distributed under the GPL-3.0+.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Gravity Forms Google Analytics Add-On 2.4.1\n"
|
||||
"Report-Msgid-Bugs-To: https://gravityforms.com/support\n"
|
||||
"Last-Translator: Gravity Forms <support@gravityforms.com>\n"
|
||||
"Language-Team: Gravity Forms <support@gravityforms.com>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"POT-Creation-Date: 2026-03-03T19:26:40+00:00\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"X-Generator: WP-CLI 2.12.0\n"
|
||||
"X-Domain: gravityformsgoogleanalytics\n"
|
||||
|
||||
#. Plugin Name of the plugin
|
||||
msgid "Gravity Forms Google Analytics Add-On"
|
||||
msgstr ""
|
||||
|
||||
#. Plugin URI of the plugin
|
||||
msgid "http://gravityforms.com"
|
||||
msgstr ""
|
||||
|
||||
#. Description of the plugin
|
||||
msgid "Integrates Gravity Forms with Google Analytics and Tag Manager"
|
||||
msgstr ""
|
||||
|
||||
#. Author of the plugin
|
||||
msgid "Gravity Forms"
|
||||
msgstr ""
|
||||
|
||||
#. Author URI of the plugin
|
||||
msgid "https://gravityforms.com"
|
||||
msgstr ""
|
||||
|
||||
#. translators: 1: reauthentication version number 2: open <a> tag, 3: close </a> tag
|
||||
#: class-gf-google-analytics.php:395
|
||||
msgid "Gravity Forms Google Analytics v%1$s requires re-authentication in order to correctly send data to Google Analytics 4. Please %2$sdisconnect and reconnect%3$s to ensure data can be sent to GA4."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:471
|
||||
msgid "Update Settings"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:472
|
||||
msgid "Disconnecting"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:473
|
||||
msgid "Redirecting..."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:474
|
||||
msgid "Connect"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:475
|
||||
msgid "Connecting"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:476
|
||||
msgid "You must select a Workspace"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:477
|
||||
msgid "You must select a View"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:478
|
||||
msgid "You must select a Google Analytics account"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:479
|
||||
msgid "You must select a Tag Manager Account"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:481
|
||||
msgid "Please select a connection type to continue."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:614
|
||||
msgid "You don't have sufficient permissions to update the form settings."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1100
|
||||
msgid "There was an error retrieving Google Analytics data streams."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1105
|
||||
msgid "Select a data stream"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1155
|
||||
msgid "Select a Container"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1190
|
||||
msgid "Could not retrieve Tag Manager workspaces"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1199
|
||||
msgid "Select a Workspace"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1448
|
||||
msgid "Nonce validation failed."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1509
|
||||
msgid "Nonce validation has failed."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1523
|
||||
msgid "User does not have required permissions to setup Google Analytics."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1537
|
||||
msgid "Unable to initialize Google Anaylics API."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1571
|
||||
msgid "Processing... Please wait."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1625
|
||||
msgid "Disconnect"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1627
|
||||
#: includes/settings/class-plugin-settings.php:188
|
||||
#: includes/settings/class-plugin-settings.php:193
|
||||
msgid "Manual Configuration"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1629
|
||||
#: includes/settings/class-plugin-settings.php:167
|
||||
#: includes/settings/class-plugin-settings.php:172
|
||||
#: includes/settings/class-plugin-settings.php:347
|
||||
msgid "Google Analytics"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1631
|
||||
#: includes/settings/class-plugin-settings.php:181
|
||||
msgid "Google Tag Manager"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1633
|
||||
#: includes/settings/class-plugin-settings.php:163
|
||||
msgid "Google Measurement Protocol"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1635
|
||||
msgid "Not connected"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1683
|
||||
msgid "Measurement ID not specified."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1831
|
||||
#: class-gf-google-analytics.php:1843
|
||||
msgid "It appears that you do not have a Google Analytics account for the account you selected."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1845
|
||||
#: class-gf-google-analytics.php:1953
|
||||
msgid "Return to Settings"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1852
|
||||
msgid "Select an account"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1858
|
||||
msgid "This account does not have any properties..."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1917
|
||||
msgid "Select a Tag Manager Account"
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:1951
|
||||
msgid "It appears that you do not have a Google Tag Manager account for the account you selected."
|
||||
msgstr ""
|
||||
|
||||
#: class-gf-google-analytics.php:2424
|
||||
msgid "No title found"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-gf-google-analytics-api.php:108
|
||||
msgid "The API mode supplied is not supported by the Google Analytics API."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:95
|
||||
msgid "Feed Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:96
|
||||
#: includes/settings/class-form-settings.php:528
|
||||
#: includes/settings/class-form-settings.php:560
|
||||
msgid "Form Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:191
|
||||
#: includes/settings/class-form-settings.php:194
|
||||
#: includes/settings/class-form-settings.php:199
|
||||
msgid "Feed Name"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:199
|
||||
msgid "Enter a feed name to uniquely identify this feed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:204
|
||||
#: includes/settings/class-form-settings.php:544
|
||||
msgid "Event Parameters"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:208
|
||||
msgid "Conditional Logic Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:212
|
||||
#: includes/settings/class-form-settings.php:214
|
||||
msgid "Conditional Logic"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:214
|
||||
msgid "When conditions are enabled, conversions will only be sent when the conditions are met."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:244
|
||||
msgid "Parameter names must be 40 characters or fewer and are limited to alphanumeric characters and underscores. They cannot begin or end with an underscore. Values are limited to 100 characters or fewer."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:245
|
||||
#: includes/settings/class-form-settings.php:290
|
||||
msgid "Parameters"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:247
|
||||
#: includes/settings/class-form-settings.php:292
|
||||
msgid "Submission Parameters"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:247
|
||||
#: includes/settings/class-form-settings.php:292
|
||||
msgid "Set the parameters that will be sent to Google Analytics for this feed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:250
|
||||
#: includes/settings/class-form-settings.php:295
|
||||
msgid "Parameter Name"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:252
|
||||
#: includes/settings/class-form-settings.php:297
|
||||
msgid "Enter a parameter name"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:255
|
||||
#: includes/settings/class-form-settings.php:301
|
||||
msgid "Parameter Value"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:257
|
||||
#: includes/settings/class-form-settings.php:303
|
||||
msgid "Enter a value"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:271
|
||||
#: includes/settings/class-form-settings.php:272
|
||||
#: includes/settings/class-form-settings.php:279
|
||||
#: includes/settings/class-form-settings.php:281
|
||||
msgid "Tag Manager Trigger"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:272
|
||||
#: includes/settings/class-form-settings.php:281
|
||||
msgid "Set the trigger that will be sent to tag manager when this feed is processed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:352
|
||||
msgid "Parameter names and values must be strings."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:356
|
||||
msgid "Parameter names must be 40 characters or less."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:360
|
||||
msgid "Parameter values must be 100 characters or less."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:364
|
||||
msgid "Parameter names cannot begin or end with an underscore, and must contain only letters, numbers, and underscores."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:502
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:505
|
||||
msgid "Trigger"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:532
|
||||
#: includes/settings/class-form-settings.php:563
|
||||
msgid "Pagination Tracking"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:536
|
||||
msgid "Enable pagination tracking"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-form-settings.php:565
|
||||
msgid "Add a Page field to your form to begin tracking pagination events."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:86
|
||||
msgid "Settings Updated."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:158
|
||||
#: includes/settings/class-plugin-settings.php:351
|
||||
msgid "Measurement Protocol"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:161
|
||||
msgid "Recommended"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:164
|
||||
msgid "The Measurement Protocol is a server-to-server connection with Google Analytics. It is the most reliable mechanism for event tracking, but it does not include data such as AdWords, Remarketing, or tracking variables."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:170
|
||||
msgid "Flexible"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:173
|
||||
msgid "Google Analytics mode will send data such as Source/Medium (e.g., the page leading to a conversion). Additionally, Google Analytics mode will send information about your user such as location, language, browser information, and AdWords/Remarketing information."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:176
|
||||
#: includes/settings/class-plugin-settings.php:355
|
||||
msgid "Tag Manager"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:179
|
||||
#: includes/settings/class-plugin-settings.php:191
|
||||
#: includes/settings/class-plugin-settings.php:546
|
||||
#: includes/settings/class-plugin-settings.php:573
|
||||
msgid "Advanced"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:182
|
||||
msgid "If you need more control after a form has been submitted, such as setting up a remarketing tag, then Google Tag Manager may be the best option."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:194
|
||||
msgid "Use this option if you are an advanced user and would like to manually enter your Google Analytics information."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:200
|
||||
msgid "Select Tracking Connection Type"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:201
|
||||
msgid "Using the Google Analytics Platform you can easily add your Google Analytics tracking code to any of your Gravity Forms, in order to track visitor behavior and demographics. We offer three ways to connect to the service."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:217
|
||||
msgid "Continue →"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:262
|
||||
msgid "Select a Google Analytics Account"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:275
|
||||
#: includes/settings/class-plugin-settings.php:311
|
||||
msgid "Complete Setup"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:297
|
||||
msgid "Select a Google Tag Manager Account"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:334
|
||||
msgid "Connection Mode"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:339
|
||||
#: includes/settings/class-plugin-settings.php:627
|
||||
#: includes/settings/class-plugin-settings.php:628
|
||||
msgid "Connection Type"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:343
|
||||
msgid "Select a connection type"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:363
|
||||
#: includes/settings/class-plugin-settings.php:640
|
||||
#: includes/settings/class-plugin-settings.php:641
|
||||
msgid "Analytics Measurement ID"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
#: includes/settings/class-plugin-settings.php:376
|
||||
msgid "Please enter the measurement ID (format: G-XXXXXX). %sLearn more about finding your measurement ID%s."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:385
|
||||
#: includes/settings/class-plugin-settings.php:579
|
||||
msgid "Google Analytics Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:390
|
||||
#: includes/settings/class-plugin-settings.php:584
|
||||
msgid "Don't Output Google Analytics Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:390
|
||||
#: includes/settings/class-plugin-settings.php:584
|
||||
msgid "Choose this option if you already have Google Analytics installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:391
|
||||
#: includes/settings/class-plugin-settings.php:585
|
||||
msgid "I already have Google Analytics installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:396
|
||||
#: includes/settings/class-plugin-settings.php:590
|
||||
msgid "Output Google Analytics Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:396
|
||||
#: includes/settings/class-plugin-settings.php:590
|
||||
msgid "Choose this option if you would like to have Google Analytics installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:397
|
||||
#: includes/settings/class-plugin-settings.php:591
|
||||
msgid "Output the Google Analytics Script."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:413
|
||||
#: includes/settings/class-plugin-settings.php:414
|
||||
#: includes/settings/class-plugin-settings.php:598
|
||||
#: includes/settings/class-plugin-settings.php:599
|
||||
msgid "UA Tracker Name"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:413
|
||||
#: includes/settings/class-plugin-settings.php:598
|
||||
msgid "Enter the Tracker Name you would like to send events from if you are using a custom Tracker for Google Analytics"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:431
|
||||
msgid "Measurement Protocol API Secret"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
#: includes/settings/class-plugin-settings.php:444
|
||||
msgid "Please enter your API secret. %1$sLearn more about finding your API secret%2$s."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:452
|
||||
msgid "Tag Manager Container ID"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
#: includes/settings/class-plugin-settings.php:456
|
||||
msgid "Please enter the container ID (format: GTM-XXXXXX). %1$sLearn more about finding your container ID%2$s."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:473
|
||||
msgid "Tag Manager Workspace ID"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: 1. Opening anchor tag with link to Gravity Forms documentation. 2. Closing anchor tag.
|
||||
#: includes/settings/class-plugin-settings.php:477
|
||||
msgid "Please enter the workspace name Id. %1$sLearn more about finding your Workspaces%2$s."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:495
|
||||
#: includes/settings/class-plugin-settings.php:552
|
||||
msgid "Google Tag Manager Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:500
|
||||
#: includes/settings/class-plugin-settings.php:557
|
||||
msgid "Don't Output the Google Tag Manager Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:500
|
||||
#: includes/settings/class-plugin-settings.php:557
|
||||
msgid "Choose this option if you already have Google Tag Manager installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:501
|
||||
#: includes/settings/class-plugin-settings.php:558
|
||||
msgid "I already have Google Tag Manager installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:506
|
||||
#: includes/settings/class-plugin-settings.php:563
|
||||
msgid "Output Google Tag Manager Script"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:506
|
||||
#: includes/settings/class-plugin-settings.php:563
|
||||
msgid "Choose this option if you would like to have Google Tag Manager installed."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:507
|
||||
#: includes/settings/class-plugin-settings.php:564
|
||||
msgid "Output the Google Tag Manager Script."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:623
|
||||
msgid "Google Analytics Settings"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:627
|
||||
msgid "Displays the current connection type. To change this, disconnect and reconnect using another type."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:633
|
||||
#: includes/settings/class-plugin-settings.php:634
|
||||
msgid "Analytics Account"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:633
|
||||
msgid "The Google Analytics Data Stream which will receive the conversion events."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:640
|
||||
msgid "The measurement ID identifies the Google Analytics Data Stream which will receive the conversion events."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:647
|
||||
msgid "Tag Manager Account"
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:674
|
||||
msgid "An error occured while connecting to the API."
|
||||
msgstr ""
|
||||
|
||||
#: includes/settings/class-plugin-settings.php:690
|
||||
msgid "Google Analytics settings have been updated."
|
||||
msgstr ""
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset
|
||||
name="The Rocketgenius coding standards"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
|
||||
>
|
||||
<description>The Rocketgenius coding standards.</description>
|
||||
|
||||
<file>lib</file>
|
||||
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="severity" value="4"/>
|
||||
<arg name="tab-width" value="4"/>
|
||||
|
||||
<!-- Exclude files -->
|
||||
<exclude-pattern>*vendor/</exclude-pattern>
|
||||
<exclude-pattern>*tests/*</exclude-pattern>
|
||||
<exclude-pattern>*tmp/*</exclude-pattern>
|
||||
<exclude-pattern>*dist/*</exclude-pattern>
|
||||
|
||||
<rule ref="WordPress.WP.I18n">
|
||||
<properties>
|
||||
<property name="text_domain" type="array">
|
||||
<element value="gravityformsgoogleanalytics"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Include the full Rocketgenius coding standard -->
|
||||
<rule ref="Rocketgenius"/>
|
||||
</ruleset>
|
||||
Reference in New Issue
Block a user