sub($trialDuration); $interval = $today->diff($accountCreationDate); $accountDuration = $interval->days; } $code = "$( document ).ready(function() { dataLayer.push({ 'UserID': '" . $clientId . "', 'Customer': 'Customer', 'PlanType': '" . $plan . "', 'Trial': '" . $isTrial . "', 'AccountDuration': '" . strval($accountDuration) . "' }); });"; //No longer sending these variables because we used to make a query to WHMCS //to fetch them, which was slow. // 'ZipCode': '" . $postcode . "', // 'Country': '" . $country . "', } catch (Exception $e) { Logging::error($e); return ""; } return $code; } /** Generate the JavaScript snippet that logs a trial to paid conversion */ public static function generateConversionTrackingJavaScript() { $newPlan = Application_Model_Preference::GetPlanLevel(); $oldPlan = Application_Model_Preference::GetOldPlanLevel(); $code = "dataLayer.push({'event': 'Conversion', 'Conversion': 'Trial to Paid', 'Old Plan' : '$oldPlan', 'New Plan' : '$newPlan'});"; return $code; } /** Return true if the user used to be on a trial plan and was just converted to a paid plan. */ public static function didPaidConversionOccur($request) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); if ($userInfo) { $user = new Application_Model_User($userInfo->id); } else { return; } $oldPlan = Application_Model_Preference::GetOldPlanLevel(); if ($user->isSuperAdmin() && !$user->isSourcefabricAdmin() && $request->getControllerKey() !== "thank-you") { //Only tracking trial->paid conversions for now. if ($oldPlan == "trial") { return true; } } return false; } }