Skip to content

Commit

Permalink
ensure SPM is loaded before the sections are called.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgundry committed Nov 30, 2017
1 parent 69ed910 commit f64a09f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 5 additions & 1 deletion classes/class-sailthru-horizon.php
Expand Up @@ -288,7 +288,11 @@ public function register_plugin_scripts() {
),
);


if ( 'personalize_js_custom' === $options['sailthru_js_type'] ) {

$params['isCustom'] = true;

// override defaults
if ( 'false' === $options['sailthru_js_auto_track_pageview'] ) {
$params['options']['autoTrackPageview'] = (bool) false;
Expand All @@ -305,7 +309,7 @@ public function register_plugin_scripts() {

if ( ! is_404() && ! is_preview() && apply_filters( 'sailthru_add_spm_js', true ) ) {
wp_enqueue_script( 'personalize_js', '//ak.sail-horizon.com/spm/spm.v1.min.js' );
wp_register_script( 'tag', plugin_dir_url( __DIR__ ) . 'js/tag.js' );
wp_register_script( 'tag', plugin_dir_url( __DIR__ ) . 'js/tag.js', array('jquery') );
wp_localize_script( 'tag', 'tag', $params );
wp_enqueue_script( 'tag' );
}
Expand Down
14 changes: 8 additions & 6 deletions js/tag.js
@@ -1,10 +1,12 @@
if (tag.isCustom) {
Sailthru.init({
customerId: tag.options.customerId,
isCustom: true,
autoTrackPageview: tag.options.autoTrackPageview,
useStoredTags: tag.options.useStoredTags,
excludeContent: tag.options.excludeContent,
jQuery(function($) {
Sailthru.init({
customerId: tag.options.customerId,
isCustom: true,
autoTrackPageview: tag.options.autoTrackPageview,
useStoredTags: tag.options.useStoredTags,
excludeContent: tag.options.excludeContent,
});
});
} else {
Sailthru.init({
Expand Down
4 changes: 2 additions & 2 deletions views/widget.scout.display.php
Expand Up @@ -22,9 +22,9 @@
?>
<?php if ( $use_spm ) : ?>
<div class="sailthru-spm-widget">
<div id="<?php echo esc_attr( $this->id ); ?>"></div>
<div id="<?php echo esc_attr( $this->id ); ?>-container"></div>
<script type="text/javascript">
jQuery(function() {
window.addEventListener('load', function() {
Sailthru.personalize({
sections: [
{
Expand Down

0 comments on commit f64a09f

Please sign in to comment.