All Collections
Nickelled Interactive (Advanced) Guides
Installation
Installing Nickelled Interactive Guides using PHP
Installing Nickelled Interactive Guides using PHP

How to use PHP to install Nickelled Interactive Guides on Wordpress, Laravel, Symfony, or CodeIgniter sites

cyndi@nickelled.com avatar
Written by cyndi@nickelled.com
Updated over a week ago

You can install Nickelled via PHP easily, by adding a conditional tag which listens for a PHP user ID.

1) Head to your Nickelled account at https://app.nickelled.com/

2) Click 'Settings' to open your account settings:

3) Click 'Sites' to open your sites:

4) Open the site you want to install your Flows on. Then, click 'View code snippet' to get your javascript snippet:

5) In your PHP codebase, add a conditional block which fires only if a user ID is detected.

For Wordpress, which has a built-in get_current_user_id function, this will look something like:

<?php if ( get_current_user_id() ) : ?>
// content goes here
<?php endif; ?>

For other frameworks, you probably want to call a helper method to check whether the user is logged in and has an ID:

<?php if (!empty($iCurrentlyLoggedInMemberId)): ?>
// content goes here
<?php endif; ?>

6) Inside your conditional block, add the Nickelled Flows code:

<script type="text/javascript">
(function () {
var NickelledLaunchers = window.NickelledLaunchers = NickelledLaunchers || { setUser: function (u) { this.userData = u } };
NickelledLaunchers.userData = {
appId: "YOUR_NICKELLED_APP_ID",
userId: "{{ USER_IDENTIFIER }}"
}
var s = document.createElement("script");
s.async = true;
s.src = "https://cdn.nickelled.com/launchers-2.min.js";
var f = document.getElementsByTagName("script")[0];
f.parentNode.insertBefore(s, f);
})();
</script>

Note that you'll need to tweak this code to ensure you're passing the correct Nickelled app ID (we've added the placeholder YOUR_NICKELLED_APP_ID in the code above).

7) Finally, add a PHP function to pass in the userId.

Your specific function will vary. In Wordpress, it's a fairly simple line:

<?php echo get_current_user_id(); ?>

This means your entire snippet will look something like:

<?php if ( get_current_user_id() ) : ?>
<script type="text/javascript">
(function () {
var NickelledLaunchers = window.NickelledLaunchers = NickelledLaunchers || { setUser: function (u) { this.userData = u } };
NickelledLaunchers.userData = {
appId: "YOUR_NICKELLED_APP_ID",
userId: "<?php echo get_current_user_id(); ?>"
}
var s = document.createElement("script");
s.async = true;
s.src = "https://cdn.nickelled.com/launchers-2.min.js";
var f = document.getElementsByTagName("script")[0];
f.parentNode.insertBefore(s, f);
})();
</script>
<?php endif; ?>

8) Publish your code, either on a page, a theme page (for Wordpress) or a template.

Once it's live, you'll see that your site is marked 'Code Snippet Installed' in your Nickelled settings:

Did this answer your question?