To maximize performance and integration of your website with Pushnami, you may use the Advanced Subscription and/or Update Code. This code will ONLY work for SSL Enabled (HTTPS://) Domains.
STEP 1: Obtain The Domain Subscriber API Key
The Subscriber API Key for each domain can be found by select the targeted domain in your "Admin", then "Install", and "Get Started".
The API Key is located here:
STEP 2: Select The Type of Code Desired
Below are examples of each code type with two sample Variables inserted. You can use unlimited Variables in this code if they are setup in the "Admin".
Use your data to replace the placeholders <INSERT API KEY>
, <INSERT ZIP CODE>
, and then hardcode a value of ‘true’
for the Variable "convert" (which is a great way to know if a subscriber has converted).
There Are Three Advanced Code Options:
1· Advanced Subscribe – This code allows you to insert values for Variables directly into the subscription code that will be attached to the subscriber information when they subscribe. This code is optimal to pass variables that may not be detectable in the browser URL.
Example Advanced Subscribe Code:
<script type="text/javascript">
(function(document, window){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://api.pushnami.com/scripts/v1/push/<INSERT API KEY>";
script.onload = function() {
Pushnami.setVariables({
zip : '<INSERT ZIP CODE>',
conversion : 'true'
});
};
document.getElementsByTagName("head")[0].appendChild(script);
})(document, window);
</script>
2· Update Subscriber – When placed on a web page, the code will update the subscriber Variables when a current subscriber is detected. It will NOT offer visitors the option to subscriber to notifications and the opt-in box will NOT appear. Variables can be passed in the update code to update and Pushnami will attempt to detect variables in the URL as a secondary measure. ie: If variable zipcode is inserted into the Update Subscriber code and is also present in the URL, Pushnami will go update based on the value in the Update Code. Blank values will not update/overwrite Variables already present for the subscriber in Pushnami.
Example Update Subscriber Code:
<script type="text/javascript">
function updatePushSubscriber(subscriberVariables){
var psid = localStorage.getItem('pushnamiSubscriberId');
if (!psid) return; // Return if not subscribed
subscriberVariables.svu = true; // Set subscriber variable update key
var data = {sub:{},urlParams:subscriberVariables,subscriberId:psid};
return fetch('https://api.pushnami.com/api/push/subscribe', { method: 'POST', body: JSON.stringify(data), mode: 'cors', redirect: 'follow', headers: new Headers({key: '<INSERT API KEY>'})})
.catch(function(err) {
console.error("Error updating subscriber: ", err);
})
}
updatePushSubscriber({
zip: '<INSERT ZIP CODE>',
conversion : 'true'
});
</script>
3· Advanced Subscribe+Update – This code combines both features above and will attempt to subscribe any new visitors or update the Variables of current subscribers.
Example Advanced Subscribe+Update:
<script type="text/javascript">
(function(document, window){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://api.pushnami.com/scripts/v1/push/<INSERT API KEY>";
script.onload = function() {
Pushnami.update({
zipcode : '<INSERT ZIP CODE>',
convert : 'true'
});
};
document.getElementsByTagName("head")[0].appendChild(script);
})(document, window);
</script>