Skip to content

Instantly share code, notes, and snippets.

@vwo-kb
vwo-kb / syncphpImplementation.js
Last active August 28, 2019 09:13
If you have a PHP implementation, the following configuration needs to be installed before the VWO Smart Code.
window.VWO = window.VWO || [];
VWO.push(['config', {
storage: {
// enter the full url of the sync script
syncUrl: 'https://somewebsite.com/sync.php'
}
}]);
@vwo-kb
vwo-kb / syncnodeJsImplementation.js
Last active January 22, 2020 09:44
If you have a Node.js implementation, the following configuration needs to be installed before the VWO Smart Code.
window.VWO = window.VWO || [];
VWO.push(['config', {
storage: {
// enter the full url of the sync script
syncUrl: 'https://somewebsite.com/sync'
}
}]);
@vwo-kb
vwo-kb / cookieDontExpire.php
Last active January 22, 2020 09:51
With the following script example added, cookies don’t expire and VWO don’t need to rely on local storage at all.
<?php
if (array_key_exists('HTTP_ORIGIN', $_SERVER)) {
header('Access-Control-Allow-Origin: ' . $_SERVER["HTTP_ORIGIN"]);
} else {
header('Access-Control-Allow-Origin:*');
}
header('Access-Control-Allow-Credentials:true');
foreach ($_COOKIE as $key => $value) {
if (preg_match('/^(_vis_opt|_vwo)/', $key)) {
// Expire any VWO cookies after 10 years.
@vwo-kb
vwo-kb / syncjsnodeJsImplementation.js
Last active November 21, 2020 02:34
Sync.js, Node.js Implementation
/**
* The following functions reads cookies created by VWO from request and syncs them back to client
*/
function syncCookies(request, response) {
let cookies = request.headers.cookie;
const responseHeaders = {
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": request.headers.origin ? request.headers.origin : "*"
};
if (!cookies) {
<!-- VWO One Smartcode (Replace <ACCOUNTID> with your VWO account id) -->
< script src = "https://dev.visualwebsiteoptimizer.com/lib/<ACCOUNTID>.js" > < /script> < !--VWO One Smartcode ends -->
< script src = "https://dev.visualwebsiteoptimizer.com/lib/45.js" > < /script>
<!-- VWO One Smartcode (Replace <ACCOUNTID> with your VWO account id) -->
< script src = "https://dev.visualwebsiteoptimizer.com/lib/<ACCOUNTID>_nojq.js" > < /script> < !--VWO One Smartcode ends -->
< script src = "https://dev.visualwebsiteoptimizer.com/lib/45_nojq.js" > < /script>
window.VWO = window.VWO || [];
window.VWO.push(['activate', {
virtualPageUrl: 'NEW_VIRTUAL_PAGE_URL'
}]);
public IActionResult SyncCookies() {
foreach(string cookieName in Request.Cookies.Keys) {
string pattern = @ "^(_vis_opt_|_vwo).*";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
Match match = regex.Match(cookieName);
if (match.Success) {
string cookieValue = Request.Cookies[cookieName];
CookieOptions option = new CookieOptions();
UInt64 expiry = 315360000000 UL;
// Expire any VWO cookies after 10 years.