Convio Drupal : Source Code Tracking

Convio Drupal > Source Code Tracking

Overview

Drupal CMS supports C360 source code tracking.

Requirements

  1. When a user visits a Drupal page with a source code (i.e., s_src or s_subsrc URL query parameter) and then signs-up or takes action in C360, the source code is mapped to the user's profile.

Design

The Drupal Source Code Tracking implementation is tied into the SSO implementation (Part 2).

  1. At the start of each request, Drupal checks for source code URL query parameters.
  2. If a source code parameter is discovered, it is stripped from the URL query.
  3. The source codes are passed to C360 via a loginTest call. This is the same call used to (re)establish the C360 user context in Drupal.
  4. Redirect back to the originally requested page w/o the source codes.

//modules/convio.module.php

/**
 * Adds standard includes to every page.
 *
 * 1) Open API JS lib and init script -> <head>
 * 2) Session tracking beacon -> header region
 * 3) Keep-alive beacon -> footer region
 */
function _convio_add_includes() {
  static $included = FALSE;
  if (!$included) {

    // Establish a new C360 session if one doesn't exist already.
    if (ConvioLoginHandler::getInstance()->newUserSession()) {
      return;
    }

    ...
  }
  $included = TRUE;
}

// Include Convio module JS libraries on every page.
_convio_add_includes();

//modules/convio/ConvioLoginHandler.inc

  public function newUserSession() {

    // Only establish the session if none is in place yet OR if there is a source code in the request URI.
    if (! isset($_SESSION[ConvioConstants::$SESSION_CONS_ID]) || $this->hasSourceCode()) {

      // Default the Drupal user to the anonymous user. 
      // If C360 is unresponsive, then the user will be treated as the anonymous user.
      $_SESSION[ConvioConstants::$SESSION_CONS_ID] = 0;

      // Synch the COM session with the Drupal session.
      // 1) Make loginTest API call to get the COM user.
      // 2) Redirect to //convio/session/validate to establish the Drupal user session.
      // 3) Redirect back to the original request URI.

      $api_config = ConvioConfiguration::getInstance();

      $auth_url = url("convio/session/validate", 
                      array("absolute" => TRUE,
                            "query" => $this->getDestination() . "&cons_id=\${loginResponse/cons_id}&token=\${loginResponse/token}"));

      $anon_url = url("convio/session/validate",
                      array("absolute" => TRUE,
                            "query" => $this->getDestination() . "&code=\${errorResponse/code}&message=\${errorResponse/message}"));

      $params = array("api_key" => $api_config->getPublicKey(),
                      "v" => ConvioConstants::$CONS_API_VERSION,
                      "method" => "loginTest",
                      "sign_redirects" => "true",
                      "success_redirect" => $auth_url,
                      "error_redirect" => $anon_url,
                      );
      $this->addSourceCodes($params);

      $url = $api_config->getURI() . ConvioConstants::$CR_CONS_API . "?" . http_build_query($params, NULL, "&");

      drupal_goto($url);
      return TRUE;
    }

    return FALSE;
  }

  private function hasSourceCode() {
    $has_source_codes = FALSE;
    $s_src = trim($_REQUEST["s_src"]);
    $s_subsrc = trim($_REQUEST["s_subsrc"]);
    if (! empty($s_src) || ! empty($s_subsrc)) {
      $has_source_codes = TRUE;
    }
    return $has_source_codes;
  }

  private function addSourceCodes(&$params) {
    $s_src = trim($_REQUEST["s_src"]);
    if (! empty($s_src)) {
      $params["s_src"] = $s_src;
    }

    $s_subsrc = trim($_REQUEST["s_subsrc"]);
    if (! empty($s_subsrc)) {
      $params["s_subsrc"] = $s_subsrc;
    }
  }

Caveats

There are several caveats to be aware of when integrating Drupal with C360:

  • Like the SSO implementation, the source code tracking mechanism is not designed to be fault tolerant should COM become unavailable or unresponsive. Source code tracking will not work because of the timed-out SSO redirects.


-- Michael Pih (mpih@convio.com) - 20 July 2010
Copyright (C) 2010 Convio, Inc. All rights reserved. This program is free open source 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 2 of the License, or (at your option) any later version. The GNU General Public License is available at http://www.gnu.org/licenses/.