Skip to content

Commit

Permalink
Merge pull request #13 from CODESIGN2/1.0.8-work
Browse files Browse the repository at this point in the history
1.0.8 Features
  • Loading branch information
Lewiscowles1986 authored Feb 18, 2021
2 parents 2a8cc9a + c099ea3 commit 7854d1b
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 38 deletions.
54 changes: 19 additions & 35 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
Plugin Name: CD2 FullStory Integration
Description: This plugin is designed to Integrate the fullstory platform with WordPress. Plugin Targets PHP7, don't try running on 5.x branch
Author: LewisCowles
Version: 1.07
Version: 1.08
Author URI: https://www.codesign2.co.uk/
*/

if(!defined('FULLSTORY_ORG')) { // Why do this? Oh yeah because automated installs via ansible or shell-script
define('FULLSTORY_ORG', '00000');
}

function fullstory_get_org() {
function cd2_fullstory_get_org() {
return esc_attr(get_option('fullstory_org_code', FULLSTORY_ORG));
}

function cd2_fullstory_get_snippet() {
$install_overwrite_path = WP_CONTENT_DIR . '/fullstory/snippet.js';
if(file_exists($install_overwrite_path) && is_readable($install_overwrite_path)) {
return file_get_contents($install_overwrite_path);
}
return file_get_contents(__DIR__ . '/js/fs-snippet.js');
}

function render_cd2_fullstory_settings_page() {
?><h3>FullStory Settings</h3>
<form method="post" action="options.php">
Expand All @@ -31,23 +39,7 @@ function render_cd2_fullstory_settings_page() {
</tr>
</table>
<script type="text/javascript">
(function() {
/*
* Helper to extract FullStory Org code from URL
*/
const SCHEME_INDICATOR = '://';
const URL_PATH_SEPARATOR = '/';
const FULLSTORY_DOMAIN_INDICATOR = 'app.fullstory.com';

document.querySelector('#fullstory_org_code').addEventListener('input', function(event) {
const curInput = event.target;
const curValue = curInput.value;
if (curValue.includes(SCHEME_INDICATOR) && curValue.includes(FULLSTORY_DOMAIN_INDICATOR)) {
const urlParts = curValue.split(URL_PATH_SEPARATOR);
curInput.value = urlParts.length > 5 ? urlParts[4] : curValue;
}
});
})();
<?= file_get_contents(__DIR__ . '/js/admin.js'); ?>
</script>
<?php submit_button(); ?>
</form><?php
Expand All @@ -60,7 +52,7 @@ function render_cd2_fullstory_settings_page() {
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), function($links) {
$mylinks = [
'<a href="' . admin_url( 'options-general.php?page=cd2-fullstory-wordpress-integration' ) . '">Settings</a>',
'<a href="https://github.com/Lewiscowles1986/cd2-fullstory-integration/">Source Code (GitHub)</a>',
'<a href="https://github.com/CODESIGN2/wordpress-fullstory-integration/">Source Code (GitHub)</a>',
];
return array_merge( $links, $mylinks );
} );
Expand Down Expand Up @@ -90,23 +82,13 @@ function render_cd2_fullstory_settings_page() {

add_action( 'wp_head', function() {
?>
<?php if(apply_filters('cd2_enable_fstory', true) && apply_filters('cd2_disable_fstory_admin', !is_admin())): ?>
<!-- FullStory WP Integration -->
<script>
window['_fs_debug'] = false;
window['_fs_host'] = 'fullstory.com';
window['_fs_org'] = '<?= fullstory_get_org() ?>';
window['_fs_namespace'] = 'FS';
(function(m,n,e,t,l,o,g,y){
if (e in m && m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].'); return;}
g=m[e]=function(a,b){g.q?g.q.push([a,b]):g._api(a,b);};g.q=[];
o=n.createElement(t);o.async=1;o.src='https://'+_fs_host+'/s/fs.js';
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
g.identify=function(i,v){g(l,{uid:i});if(v)g(l,v)};g.setUserVars=function(v){g(l,v)};
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
g.clearUserCookie=function(c,d,i){if(!c || document.cookie.match('fs_uid=[`;`]*`[`;`]*`[`;`]*`')){
d=n.domain;while(1){n.cookie='fs_uid=;domain='+d+
';path=/;expires='+new Date(0).toUTCString();i=d.indexOf('.');if(i<0)break;d=d.slice(i+1)}}};
})(window,document,window['_fs_namespace'],'script','user');
window['_fs_debug'] = '<?= apply_filters('cd2_fstory_debug_enable', false) ? 'true' : 'false'; ?>';
window['_fs_org'] = '<?= cd2_fullstory_get_org() ?>';

<?= apply_filters('cd2_fstory_snippet', cd2_fullstory_get_snippet()); ?>
</script>
<?php if (is_user_logged_in()): ?><?php $current_user = wp_get_current_user(); ?><?php $current_user_data = get_userdata(get_current_user_id()); ?>
<script>
Expand All @@ -124,8 +106,10 @@ function render_cd2_fullstory_settings_page() {
data["<?= $key; ?>"] = <?= $value; ?>; <?php // ensure you enclose strings ?>
<?php endforeach; ?>
FS.identify(wpUsername, data);
FS.consent(<?= apply_filters('cd2_fstory_consent_to_protected_fields', false) ? 'true' : 'false' ?>);
})();
<?php endif; ?>
<?php endif; ?>
</script>
<?php
} );
Expand Down
17 changes: 17 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(function() {
/*
* Helper to extract FullStory Org code from URL
*/
const SCHEME_INDICATOR = '://';
const URL_PATH_SEPARATOR = '/';
const FULLSTORY_DOMAIN_INDICATOR = 'app.fullstory.com';

document.querySelector('#fullstory_org_code').addEventListener('input', function(event) {
const curInput = event.target;
const curValue = curInput.value;
if (curValue.includes(SCHEME_INDICATOR) && curValue.includes(FULLSTORY_DOMAIN_INDICATOR)) {
const urlParts = curValue.split(URL_PATH_SEPARATOR);
curInput.value = urlParts.length > 5 ? urlParts[4] : curValue;
}
});
})();
20 changes: 20 additions & 0 deletions js/fs-snippet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
window['_fs_host'] = 'fullstory.com';
window['_fs_script'] = 'edge.fullstory.com/s/fs.js';
window['_fs_namespace'] = 'FS';
(function(m,n,e,t,l,o,g,y){
if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}
g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];
o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src='https://'+_fs_script;
y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);
g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};
g.anonymize=function(){g.identify(!!0)};
g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};
g.log = function(a,b){g("log",[a,b])};
g.consent=function(a){g("consent",!arguments.length||a)};
g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};
g.clearUserCookie=function(){};
g.setVars=function(n, p){g('setVars',[n,p]);};
g._w={};y='XMLHttpRequest';g._w[y]=m[y];y='fetch';g._w[y]=m[y];
if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)};
g._v="1.3.0";
})(window,document,window['_fs_namespace'],'script','user');
38 changes: 35 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: LewisCowles,CD2Team
Tags: integrate, integration, ux, user experience, user-experience, fullstory, cd2, codesign2, lewiscowles, user behaviour, user recording, metrics, user insight, woocommerce analytics, woocommerce monitoring, customer profile, replay user session
Requires at least: 4.6
Tested up to: 5.3.2
Tested up to: 5.7.0
Requires PHP: 5.6
Stable tag: 1.0.7
Stable tag: 1.0.8
License: GPLv3

== Description ==
Expand All @@ -24,13 +24,45 @@ The plugin does no special work apart from ensuring that attributes are escaped

Care has been taken to supply the following filters, so that you can specify your own custom fullstory attributes.

* cd2_fstory_data
* cd2_fstory_data (array)

If using custom filters, please note you are wholely responsible for not messing things up. I recommend using a sibling plugin rather than editing this one; as well as testing locally, perhaps in staging before deploying to production as FullStory does not love malformed data. The format of data is simply key-value in a PHP array which is merged with the default array.

This is a reference plugin, I'd love to develop it further, or work with you or your business to include additional features, perhaps a hooks interface or more formal view-separation for complex projects. I've used this on Multisite, Standard WP, multi-lingual sites.

== Changelog ==
= 1.0.8 =
**Added**

* Hook `cd2_enable_fstory` which allows custom plugins to disable the fullstory integration by returning false from filter. It's true by default. Just deactivate the plugin if you don't want to use.
* Hook `cd2_disable_fstory_admin` which allows custom plugins to enable fullstory integration in the admin area by returning true from filter. Importantly, `cd2_enable_fstory` also needs to be true.
* Hook `cd2_fstory_debug_enable` which allows custom plugins to enable debug mode by returning true from filter.
* Hook `cd2_fstory_snippet` allows custom plugins to enable using alternative JavaScript when integrating with FullStory.
* Ability to edit FullStory plugin JavaScript using files (source control vs database call) by editing the plugin or creating a `snippet.js` within a `fullstory` directory, inside your `wp-content` direcotry.

**Changed**

* Reported WordPress compatibility (after tests).
* Disabling logic.
* Plugin source code (following moving to the CD2 org)

**Fixed**

* N/A

= 1.0.7 =
**Added**

* N/A

**Changed**

Reported WordPress compatibility (after tests)

**Fixed**

* N/A

= 1.0.6 =
**Added**

Expand Down

0 comments on commit 7854d1b

Please sign in to comment.