Todas as coleções
Instalação, Integração e Configuração
Segmentação manual | O inscrito seleciona as categorias de interesse
Segmentação manual | O inscrito seleciona as categorias de interesse

Neste guia vamos te ensinar a criar um mecanismo em que o inscrito em push consegue se segmentar nas categorias que pretende

Amanda Antunes avatar
Escrito por Amanda Antunes
Atualizado há mais de uma semana

Passo 1:

Na configuração avançada do Site, habilite os callbacks de javascript para o eventos "newSubscription" e "load" -- você pode aprender a fazer isso aqui.

Atenção: O "load" será necessário apenas se você já tiver inscritos que não selecionaram nenhum Interesse e quiser que o popup de Interesses apareça para eles.

Passo 2:

Utilize o seguinte código exemplo no seu site

Você pode adaptar os estilos conforme precisar :)

<style>
#pn-category-container {
border: 1px solid #dadada;
border-radius: 5px;
padding: 16px;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 630px;
background: #fbfbfb;
transition: visibility 600ms, opacity 600ms;
visibility: hidden;
display: none;
}


#pn-category-container input {
margin-left: 0;
}


#pn-category-container label {
margin-right: 10px;
}


#pn-category-container p {
margin: 0;
line-height: 28px;
}


#pn-category-container .thank-you {
font-weight: 700;
}


#pn-category-container .inline {
display: inline-block;
}


#pn-category-container .close-btn {
border: none;
background-color: #37AAF3;
padding: 6px 10px;
color: #fff;
border-radius: 3px;
}


#pn-category-container .pn-mdl-header {
padding-bottom: 10px;


}
#pn-category-container .pn-mdl-footer {
padding-top: 15px;
}
</style>


<!-- Pushnews categories box (it will only be visible when a new Push Subscriber is detected) -->
<div id="pn-category-container">
<div class="pn-mdl-header">
<p class="thank-you">Obrigado por se cadastrar nas Push Notifications!</p>
</div>
<div class="pn-mdl-body">
<div class="inlinea">
<p>Quais os assuntos do seu interesse?</p>
</div>
<div class="inlinea">
<input type="checkbox" name="pushnews-category" value="geral" id="pn-category-1">
<label for="pn-category-1">Geral</label>


<input type="checkbox" name="pushnews-category" value="esportes" id="pn-category-2">
<label for="pn-category-2">Esportes</label>


<input type="checkbox" name="pushnews-category" value="economia" id="pn-category-3">
<label for="pn-category-3">Economia</label>


<input type="checkbox" name="pushnews-category" value="politica" id="pn-category-4">
<label for="pn-category-4">Política</label>
</div>
</div>
<div class="pn-mdl-footer">
<button class="close-btn">× Fechar</button>
</div>
</div>
<script>
var IlabsPush = IlabsPush || [];


/**
* When a new Push Subscription is detected, show the Interests box
* Set the Interests box as displayed
*/
function pushnewsNewSubscriptionHandler(event) {
if (true === event.data.isSubscribed) {
var pushnewsId = event.data.pnId;

localStorage.setItem("pnews_interestsAlreadyDisplayed", 1);
document.getElementById("pn-category-container").style.visibility = "visible";
document.getElementById("pn-category-container").style.display = "block";
}
}

/**
* When the Pushnews tag loads, if user is subscribed but the Interests box was not displayed,
* show the Interests box as well.
* This function is only needed if you want the visitors of your site, that did not have the
* opportunity to select Interests, to show them afterwards
*/
function pushnewsLoadHandler(event) {
var subscriberInfo = event.IlabsPush.getSubscriberInformation();
if (subscriberInfo && subscriberInfo.isSubscribed && localStorage.getItem("pnews_interestsAlreadyDisplayed") != '1') {
localStorage.setItem("pnews_interestsAlreadyDisplayed", 1);
document.getElementById("pn-category-container").style.visibility = "visible";
document.getElementById("pn-category-container").style.display = "block";
}
}

/**
* When a category is clicked, sync with Pushnews
*/
var pnCategories = document.querySelectorAll("input[name=pushnews-category]");
if (null !== pnCategories) {
pnCategories.forEach(function(pnCategory) {
pnCategory.addEventListener("change", function(event) {
var categoryName = this.getAttribute('value');
var categoryValue = "0";
if (true === this.checked) {
categoryValue = "1";
}
var customFilters = {};
customFilters[categoryName] = categoryValue;

IlabsPush.push(["sendCustomFilters", customFilters]);
})
});


}


/**
* When the close button is clicked, close the categories box
*/
document.querySelector("#pn-category-container .close-btn").addEventListener("click", function(event) {
event.preventDefault();
document.getElementById("pn-category-container").style.visibility = "hidden";
document.getElementById("pn-category-container").style.display = "none";
});
</script>

Respondeu à sua pergunta?