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 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'
}]);
app.UseMvc(routes => {
routes.MapRoute("cookies", "sync", defaults: new {
controller = "Cookies", action = "SyncCookies"
});
});
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.
using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Text.RegularExpressions;
namespace YourApplication.Controllers {
public class CookiesController: Controller {
[HttpGet]
public IActionResult SyncCookies() {
@vwo-kb
vwo-kb / customURLForSPA
Created September 9, 2019 08:23
Using Custom URLs for SPA
window.VWO = window.VWO || [];
window.VWO.push(['activate', {
customUrl: 'http://mycustomurl.com/custom-url'
}]);