function wpan_send_form_tracking_event($entry, $form) { global $post; $msg = "About to send form tracking event to Google Analytics..."; wpan_log_debug($msg); GFCommon::log_debug($msg); /* Extract the plugin options from the database */ $options = wpan_get_options(); $tracking_uid = isset($options['tracking_uid']) ? $options['tracking_uid'] : ''; $debug = isset($options['debug']) ? $options['debug'] : ''; $form_title = $form['title']; /* I have taken the following four lines of code from https://github.com/theiconic/php-ga-measurement-protocol; thank you! */ $document_path = str_replace(home_url(), '', $entry['source_url']); $document_location = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['REQUEST_URI']; $document_title = isset($post) && get_the_title($post) ? get_the_title($post) : 'no title'; /* Setup the class */ $ga_options = ['client_create_random_id' => true, 'client_fallback_id' => 555, 'client_id' => null, 'user_id' => null, 'adapter' => ['async' => true, 'ssl' => false]]; /* Connect to tracker */ $gatracking = new \Racecore\GATracking\GATracking($tracking_uid, $ga_options); /* Build GA event */ $event = $gatracking->createTracking('Event'); $event->setAsNonInteractionHit(false); $event->setEventCategory('Contact'); $event->setEventAction($form_title); $event->setEventLabel($document_path); $event->setDocumentPath($document_path); $event->setDocumentLocation($document_location); $event->setDocumentTitle($document_title); /* Send event to GA severs */ $response = $gatracking->sendTracking($event); /* Debug */ if ($debug) { wpan_log_debug("Sent the following event to Google Analytics:"); wpan_log_debug($event); wpan_log_debug("Received the following respons from Google Analytics (ASYNC, so it might be empty): "); wpan_log_debug($response); // wpan_log_debug( "This is the form that triggered the event:" ); // wpan_log_debug( $form ); // wpan_log_debug( "This is the entry of the form in Gravity Forms:" ); // wpan_log_debug( $entry ); } }
/** * Define directories where the syntax highglighting library can be found. * * In order to provide syntax highlighting in HTML text areas, we use * the CodeMirror Javascript library (https://codemirror.net/). */ function wpan_load_syntax_highlighting() { define("WPAN_CODEMIRROR_DIR", WPAN_PLUGIN_DIR . 'vendor/codemirror/'); define("WPAN_CODEMIRROR_URL", WPAN_PLUGIN_URL . 'vendor/codemirror/'); if (file_exists(WPAN_CODEMIRROR_DIR)) { define("WPAN_SYNTAX_HIGHLIGHTING_LOADED"); wpan_log_debug("Syntax highlighting library loaded."); return true; } else { wpan_log_debug("Could not load syntax highlighting library; folder " . WPAN_CODEMIRROR_DIR . " could not be found."); } }