Pixels, iFrame and serverside PHP

Cookie control SDK implementation for Pixel tags, iFrames and serverside PHP

Anna Madsen avatar
Written by Anna Madsen
Updated over a week ago

Some cookies are set by tracking pixels or iFrames. An example of this is Facebook-pixel which many businesses use. Tracking pixels and iframes are handled by the js library in the same way as external scripts.

Tracking pixels

Original code:

<img src="https://example.marketing.com" />

Using the cookie control SDK and setting the cookie_cat_category to marketing:

<img src="" data-consent-src="https://example.marketing.com" data-category-consent="cookie_cat_marketing" />

iFrames

Original code:

<iframe src="https://someiframe.statistics.com"></iframe>

Using the cookie control SDK and setting the cookie_cat_category to statistic:

<iframe src="" data-consent-src="https://someiframe.statistics.com"data-category-consent="cookie_cat_statistic"></iframe>

Configuring external scripts, pixel trackers, and iframes are based on the same rules. They are just different HTML elements.

Setting other attributes in elements does not affect the way that the js library and the cookie control SDK work. So, for example, we can add "id", "class", etc to the element and it won't break.

<iframe id="someiframe" class="col-md-5 red-border" src=""
data-consent-src="https://someiframe.statistics.com"
data-category-consent="cookie_cat_statistic"></iframe>

The cookie control SDK only needs to have data-consent-src and data-category-consent set and have src set to an empty string "".

Serverside PHP

<?php if (isset($_COOKIE["CookieInformationConsent"]))
{
$php_json = json_decode(preg_replace('/\s*:\s*([a-zA-Z0-9_]+?)([}\[,])/', ':"$1"$2', preg_replace('/([{\[,])\s*([a-zA-Z0-9_]+?):/', '$1"$2":', str_replace("'", '"', stripslashes($_COOKIE["CookieInformationConsent"])))));
$cookieInformationConsent = $php_json->consents_approved;
$functional = 'cookie_cat_functional';
$statistic = 'cookie_cat_statistic';
$marketing = 'cookie_cat_marketing';
if (in_array($functional, $cookieInformationConsent))
{
echo '<p>Functional is enabled</p>';
}
else
{
echo '<p>Functional is disabled</p>';
}
if (in_array($statistic, $cookieInformationConsent))
{
echo '<p>Statistic is enabled</p>';
}
else
{
echo '<p>Statistic is disabled</p>';
}
if (in_array($marketing, $cookieInformationConsent))
{
echo '<p>Marketing is enabled</p>';
}
else
{
echo '<p>Marketing is disabled</p>';
}
} ?>

Related articles:

Did this answer your question?