Strategies

Website can have multiple strategies.

When relying on auto interactions without specifying a trigger, the strategy in question must be set to active.

Retrieve a Strategy

GET /v1/{access-token}/strategy
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

$api->Get('strategy')
    ->Where([
        'modid' => $modid,
    ])
    ->As('GetStrategy');

                            
                            {"profileid":"profile-c2300300a5075ee8adae51da57c39f90","siteid":"web-169b185e8dc05ad610a6e3a50a6e3712","modid":"mod-d2bee61964ff44202fde3f2d315317b7","created":"2019-01-17 15:29:12","lastupdate":"2019-02-25 15:16:04","name":"Master Strategy","status":"off","type":"full-circle","globaldelay":"2195","initialmodule":"module-385be955cf827c856ce8debb1d9d3513","recycle":"yes","lastused":null,"delay":"30","moduleid":null,"onsubmit":null,"ondismiss":null}
                            

Finding Strategies

GET /v1/{access-token}/strategies
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

// Find strategies.
$api->Find('strategies')
    ->Where([
        'siteid' => $siteid,
    // Store all strategies.    
    ])
    ->As('FindStrategies');
 
 
// Find strategies, and keep the first strategy.
$api->Find('strategies')
    ->Where([
        'siteid' => $siteid,
    // Store the first strategy only.    
    ])
    ->As('FindStrategy', 0);
 
 
                            
                            
// All stored strategies.
[{
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "modid": "mod-d2bee61964ff44202fde3f2d315317b7",
    "created": "2019-01-17 15:29:12",
    "lastupdate": "2019-02-25 15:16:04",
    "name": "Master Strategy",
    "delay": "2195",
    "initialmodule": "module-385be955cf827c856ce8debb1d9d3513",
    "recycle": "yes",
    "lastused": null,
    "delay": "30",
    "moduleid": null,
    "onsubmit": null,
    "ondismiss": null
}, {
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "modid": "mod-f31f3263e2e5a45c8c7d3a3f20e6bf23",
    "created": "2019-02-16 10:44:46",
    "lastupdate": "2019-02-19 16:41:56",
    "name": "Holidays Strategy",
    "delay": null,
    "initialmodule": null,
    "recycle": null,
    "lastused": null,
    "moduleid": null,
    "onsubmit": null,
    "ondismiss": null
}]

// The first stored strategy.
{
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "modid": "mod-d2bee61964ff44202fde3f2d315317b7",
    "created": "2019-01-17 15:29:12",
    "lastupdate": "2019-02-25 15:16:04",
    "name": "Master Strategy",
    "delay": "2195",
    "initialmodule": "module-385be955cf827c856ce8debb1d9d3513",
    "recycle": "yes",
    "lastused": null,
    "delay": "30",
    "moduleid": null,
    "onsubmit": null,
    "ondismiss": null
}
                            

Create a Strategy

POST /v1/{access-token}/strategy
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

$api->Create('strategy')
    ->Attributes([
        'siteid' => $siteid,
        'name' => 'My First Strategy',
    ])
    ->As('CreateStrategy');
 
                            
                            
{
    "lastused": "2019-02-27 16:35:01",
    "created": "2019-02-27 16:35:01",
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "modid": "strategy-a8371dd97396162ea8db5a12113685d6",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "name": "My First Strategy"
}
                            

Update Strategy

PUT /v1/{access-token}/strategy
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

$api->Get('strategy')
    ->Where([
        'modid' => $modid,
    ])
    ->Update([
        'type' => 'full-circle',
        'initialmodule' => $moduleid,
        'recycle' => 'yes',
        'globaldelay' => 1000
    ])
    ->As('UpdateStrategy');

                            
                            
{
    "profileid": "profile-c2300300a5075ee8adae51da57c39f90",
    "siteid": "web-169b185e8dc05ad610a6e3a50a6e3712",
    "modid": "mod-d2bee61964ff44202fde3f2d315317b7",
    "created": "2019-01-17 15:29:12",
    "lastupdate": "2019-02-25 15:16:04",
    "name": "Master Strategy",
    "initialmodule": "module-ce3b159e2b4093ea5ed8f654f49a6333",
    "recycle": "yes",
    "lastused": null,
    "delay": "30",
    "moduleid": null,
    "onsubmit": null,
    "ondismiss": null
}
                            

Delete a Strategy

DELETE /v1/{access-token}/strategy
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

$api->Get('strategy')
    ->Where([
        'modid' => $modid,
    ])->Delete()
    ->As('DeleteMyStrategy');
 
                            
                            
{
    "code": 200,
    "messages": ["Item removed"],
    "AccessPoint": "754a3683204940fd0f6ac39b25d127e3",
    "profileid": "profile-3be1fa342a520cbdf28aa43ab8edefee",
    "uri": "\/v1\/754a3683204940fd0f6ac39b25d127e3\/strategy"
}
                            

Download and Localize all Modules in a Strategy

POST /v1/{access-token}/strategy
                            
use \FormSynergy\Init as FS;

$api = FS::Api()->Load($profileid);

// Create a new resource storage for 'data'
$resource = FS::Resource('data');
/**
 * Downloading a strategy, will prepare and localize 
 * all modules within a strategy as a fallback plan.
 * Read more: https://formsynergy.com/domcumentation/localize/
 */
$api->Download('strategy')
    ->Where([
        'modid' => $modid
    ])
    ->As('Modules');
 
foreach( $api->_Modules() as $module ) {

    /**
     * NOTE: The javaScript client, will be expecting interaction data,
     * including id, dataType, DomObject, placement, position...
     * 
     * Most of all interaction data can be created upon request at 
     * the exception of the DomObject.
     * DomObject: Stringified Virtual Dom object.
     *
     * Store DomObject, we can retrieve it later to create a response.
     */
    $resource
        ->Store($module['moduleid'])
        ->Data($module['DomObject']);
} 
                            
                            
// The html is base64 encoded, make sure to decoded it before storing the data.
[{
        "moduleid": "module-16a16679c94ff73fdcfa28970185bc76",
        "html": "base64(3M9Int7cHJlZml4fX0gc2hvdyBpbiIgdGFiaW5kZXg9Ii0xIi)"
    },
    {
        "moduleid": "module-0e39c9c2bb42284bb1ae8d78cade2cf2",
        "html": "base64(3M9Int7cHJlZml4fX0gc2hvdyBpbiIgdGFiaW5kZXg9Ii0xIi)"
    },
    {
        "moduleid": "module-33e6d75f3f2042e6bd8ac1df411714ea",
        "html": "base64(DQogDQogICAgPGRpdiBjbGFzcz0ie3t3cmFwX2NsYXNzX25hbWV9fSI)"
}]