1. Help Center
  2. Implementation, Deployment, and Security

Figuring out What SiteSpect is Doing on the Page

The following code is written in PHP and assumes that the client knows only the SSSC cookie and that the Campaign is setup with insightful Tags for Variation Groups:

  1. The client goes to the discovery page and retrieves the Variation Group resource through the “variationgroup” link relation and Campaign resource through “campaign” link relation.
  2. The client parses the SSSC cookie, grabs the Site ID, loops through each Variation Group and Campaign combination in the cookie and fills in the URI templates of Variation Group and Campaign resources.
  3. The client makes an API call to each Variation Group and Campaign resource, finds the name, and prints it on the screen with some other text and formatting.
<?php

//function for making cURL requests
function curl($url,$method,$data){

//cURL call
$ch = curl_init();

if($method){
curl_setopt ($ch, CURLOPT_POST, true);
if($data){
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
}
}

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-API-TOKEN: YOUR-API-TOKEN"));

$output = curl_exec($ch);

if($output !== false || curl_error($ch)) {

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($status,$output);

curl_close($ch);
}

}

//list of known variables – SSSC cookie
$sssc = "6.G5861867684635283651.6|334.3608:336.3642:367.4754";

//Location of the discovery page
$discovery = "http://admin1.sitespect.com/api"";

//call the discovery page
$request = curl($discovery);

if ($request[0] == 200){
$json = json_decode($request[1],true);

//get variation group and campaign URI resources from discovery page
$variationgroup_uri = $json['_links']['variationgroup']["href"];
$campaign_uri = $json['_links']['campaign']["href"];

// Parse the SSSC cookie, many ways to do it, I am showing a non-regex way
// Format: Site_ID.User_GUID(prefixed with a G).UserVisitCount |
TestCampaign_ID.VariationGroup_ID[:TestCampaign_ID.VariationGroup_ID:...]
$split = explode("|", $sssc);
$dot = explode(".", $split[0]);
$colon = explode(":", $split[1]);

$Site_ID = $dot[0];

//loop through each TestCampaign_ID and VariationGroup_ID combination
foreach($colon as $tcvg) {
$resplit = explode(".", $tcvg);
$TestCampaign_ID = $resplit[0];
$VariationGroup_ID = $resplit[1];

//Campaign URI Resource is a template, lets manually process that
$campaing_call = str_replace('{site-id}', $Site_ID, $campaign_uri);
$campaing_call = str_replace('{campaign-id}', $TestCampaign_ID, $campaing_call);

Variation Group URI Resource is a template, lets manually process that
$variationgroup_call = str_replace('{site-id}', $Site_ID, $variationgroup_uri);
$variationgroup_call = str_replace('{campaign-id}', $TestCampaign_ID, $variationgroup_call);
$variationgroup_call = str_replace('{variationgroup-id}', $VariationGroup_ID, $variationgroup_call);

//Retrieve and Print Campaing Name
$req = curl($campaing_call);

if($req[0] == 200){
$json = json_decode($req[1],true);
//print the name of campaign or variation group to the screen
echo "Campaign: ".$json["Name"]."<br>";
}

//Retrieve and print Variation Group name
$req = curl($variationgroup_call);

if($req[0] == 200){
$json = json_decode($req[1],true);
//print the name of campaign or variation group to the screen
echo "Variation Group: ".$json["Name"]."<br>";
}

}

}

?>