Skip to content

Commit

Permalink
⚡ (wordpress) Add query params exclusion support
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Sep 25, 2023
1 parent 90cf2e9 commit 2307231
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 52 deletions.
12 changes: 12 additions & 0 deletions apps/docs/docs/embed/wordpress.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ Of course, before using it, you need to create and publish your first typebot.

The code snippet to paste is easily configurable in the Share tab of your bot after clicking on the "Wordpress" button.

## Excluded pages

The excluded pages input is a comma-separated list of pages where you don't want your typebot to appear.

Examples:

- `/app/*` will exclude all pages starting with `/app/`
- `/app` will only exclude the `/app` page
- `/app?param=1` will only exclude the `/app` page **and** with the `param` query parameter set to `1`
- `/app?param=*` will exclude the page at `/app` **and** with the `param` query parameter set to anything
- `/app/*?param=*` will exclude all pages starting with `/app/` **and** with the `param` query parameter set to anything

## Personalize user experience

You can leverage the [prefilled variables](/editor/variables#prefilled-variables) and inject your user information directly into your typebot so that the experience is entirely customized to your user.
Expand Down
6 changes: 3 additions & 3 deletions packages/embeds/wordpress/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@typebot.io/wordpress",
"version": "3.2.0",
"version": "3.3.0",
"main": "index.js",
"repository": "https://github.com/baptisteArno/typebot.io",
"author": "baptisteArno",
"license": "AGPL-3.0-or-later",
"scripts": {
"deploy": "pnpm copy && pnpm commit",
"copy": "svn copy ./trunk ./tags/3.2.0",
"commit": "svn ci -m 'Update embed lib to 0.1'"
"copy": "svn copy ./trunk ./tags/3.3.0",
"commit": "svn ci -m 'Fix loading issue with Gravity Forms'"
}
}
5 changes: 4 additions & 1 deletion packages/embeds/wordpress/trunk/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 5.0
Tested up to: 6.0
License: GPL 2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Stable Tag: 3.2.0
Stable Tag: 3.3.0

== Description ==
Collect 4x more responses with conversational apps using Typebot.
Expand All @@ -24,6 +24,9 @@ This plugin relies on Typebot which is a tool that allows you to create conversa
3. Activate your Typebot with the "Typebot" admin button located in the sidebar

== Changelog ==
= 3.3.0 =
* Fix loading with Gravity Forms and add query params exclusion

= 3.2.0 =
* Update embed lib to 0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<div style="display: flex; flex-direction: column; margin-top: 1rem">
<label>Excluded pages (optionnal):</label>
<p style="color: gray">Example: /app/*, /user/*, /admin/settings</p>
<p style="color: gray">Example: /app/*, /user/*, /admin/settings, /app?param=*</p>
<input name="excluded_pages" value="<?php echo esc_attr(get_option('excluded_pages')); ?>" style="padding: .5rem" />
</div>

Expand Down
104 changes: 59 additions & 45 deletions packages/embeds/wordpress/trunk/public/class-typebot-public.php
Original file line number Diff line number Diff line change
@@ -1,78 +1,92 @@
<?php

class Typebot_Public
{
public function add_head_code()
public function __construct()
{
add_action('wp_head', array($this, 'parse_wp_user'));
add_action('wp_footer', array($this, 'typebot_script'));
}

public function parse_wp_user()
{
function parse_wp_user()
{
$wp_user = wp_get_current_user();
echo '<script>
$wp_user = wp_get_current_user();
echo '<script>
if(typeof window.typebotWpUser === "undefined"){
window.typebotWpUser = {
"WP ID":"' .
$wp_user->ID .
'",
$wp_user->ID .
'",
"WP Username":"' .
$wp_user->user_login .
'",
$wp_user->user_login .
'",
"WP Email":"' .
$wp_user->user_email .
'",
$wp_user->user_email .
'",
"WP First name":"' .
$wp_user->user_firstname .
'",
$wp_user->user_firstname .
'",
"WP Last name":"' .
$wp_user->user_lastname .
'",
$wp_user->user_lastname .
'"
}
}
</script>';
}
}

function typebot_script()
{
echo '<script type="module">
import Typebot from "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.1/dist/web.js";';
if (
get_option('excluded_pages') !== null &&
get_option('excluded_pages') !== ''
) {
$paths = explode(',', get_option('excluded_pages'));
$arr_js = 'const typebotExcludePaths = [';
foreach ($paths as $path) {
$arr_js = $arr_js . '"' . $path . '",';
}
$arr_js = substr($arr_js, 0, -1) . '];';
echo $arr_js;
} else {
echo 'const typebotExcludePaths = null;';
public function add_head_code()
{
$this->parse_wp_user();
}

function typebot_script()
{
echo '<script type="module">import Typebot from "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.1/dist/web.js";';
if (
get_option('excluded_pages') !== null &&
get_option('excluded_pages') !== ''
) {
$paths = explode(',', get_option('excluded_pages'));
$arr_js = 'const typebotExcludePaths = [';
foreach ($paths as $path) {
$arr_js = $arr_js . '"' . $path . '",';
}
if (get_option('init_snippet') && get_option('init_snippet') !== '') {
$arr_js = substr($arr_js, 0, -1) . '];';
echo $arr_js;
} else {
echo 'const typebotExcludePaths = null;';
}

echo 'if(!typebotExcludePaths || typebotExcludePaths.every((path) => {
let excludePath = path.trim();
if (get_option('init_snippet') && get_option('init_snippet') !== '') {
echo 'if(!typebotExcludePaths || typebotExcludePaths.every((path) => {
let [excludePath, excludeSearch] = path.trim().split("?");
const excludeSearchParams = excludeSearch ? new URLSearchParams(excludeSearch) : null;
let windowPath = window.location.pathname;
let windowSearchParams = window.location.search.length > 0 ? new URLSearchParams(window.location.search) : null;
if (excludePath.endsWith("*")) {
if(excludeSearchParams){
if(!windowSearchParams) return true
return !windowPath.startsWith(excludePath.slice(0, -1)) || !Array.from(excludeSearchParams.keys()).every((key) => excludeSearchParams.get(key) === "*" || (excludeSearchParams.get(key) === windowSearchParams.get(key)));
}
return !windowPath.startsWith(excludePath.slice(0, -1));
}
if (excludePath.endsWith("/")) {
excludePath = path.slice(0, -1);
excludePath = excludePath.slice(0, -1);
}
if (windowPath.endsWith("/")) {
windowPath = windowPath.slice(0, -1);
}
return windowPath !== excludePath;
}
if(excludeSearchParams){
if(!windowSearchParams) return true
return windowPath !== excludePath || !Array.from(excludeSearchParams.keys()).every((key) => excludeSearchParams.get(key) === "*" || (excludeSearchParams.get(key) === windowSearchParams.get(key)));
} else {
return windowPath !== excludePath;
}
})) {
' . get_option('init_snippet') . '
Typebot.setPrefilledVariables({ ...typebotWpUser });
}';
}
echo '</script>';
}
add_action('wp_head', 'parse_wp_user');
add_action('wp_footer', 'typebot_script');
echo '</script>';
}

public function add_typebot_container($attributes = [])
Expand Down
4 changes: 2 additions & 2 deletions packages/embeds/wordpress/trunk/typebot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: Typebot
* Description: Convert more with conversational forms
* Version: 3.2.0
* Version: 3.3.0
* Author: Typebot
* Author URI: http://typebot.io/
* License: GPL-2.0+
Expand All @@ -16,7 +16,7 @@
die();
}

define('TYPEBOT_VERSION', '3.2.0');
define('TYPEBOT_VERSION', '3.3.0');

function activate_typebot()
{
Expand Down

3 comments on commit 2307231

@vercel
Copy link

@vercel vercel bot commented on 2307231 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs.typebot.io
docs-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 2307231 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

se.onewebcenter.com
secretespiao.online
start.belenmotz.com
support.wawplus.com
survey1.digienge.io
surveys.essiell.com
test.botscientis.us
test.getreview.help
test.reventepro.com
typebot.stillio.app
typebot.stillio.com
vg.onewebcenter.com
wa.onewebcenter.com
web.draleticiah.com
whatsdigital.online
wordsandimagery.com
88584434.therpm.club
92109660.therpm.club
app.horadelucrar.com
app.whatisappweb.com
assistent.m-vogel.de
ativandograna.online
bium.gratirabbit.com
bot.ansuraniphone.my
bot.barrettamario.it
bot.buenanoticia.fun
bot.conhecaojogo.com
bot.cotemeuplano.com
bot.gameincrivel.com
bot.gamesimples.club
bot.grupodojo.com.br
bot.jogodofuturo.com
bot.jogoquelucra.com
bot.leadbooster.help
bot.mycompay.reviews
bot.projetodashi.com
bot.socialcliques.me
cha.onewebcenter.com
chat.febredojogo.com
chat.gnipharmahq.com
chat.hayurihijab.com
chat.jottagreens.com
chatbee.agfunnel.com
click.sevenoways.com
connect.growthguy.in
detetivepatricia.com
drapamela.gikpro.com
drgisellegarcia.site
forms.bonanza.design
hello.advergreen.com
infomakeracademy.com
kuiz.sistemniaga.com
leoborges-app.online
linspecteuremma.site
malayanboosterhq.com
menukb.wpwakanda.com
offer.botscientis.us
ore.barrettamario.it
sellmycarglasgow.com
site100seguro.online
stephanesampa.online
superglicemia.com.br
talkbot.agfunnel.com
tenorioadvogados.com
uppity.wpwakanda.com
www.acordo-certo.com
83701274.21000000.lol
87186327.21000000.one
90945247.21000000.one
97320578.21000000.one
98650901.21000000.one
abutton.wpwakanda.com
acelera.maxbot.com.br
agendaestrategica.com
aidigitalmarketing.kr
atendimento.vrauu.com
bbutton.wpwakanda.com
bot.anovaerarb.online
bot.coachayongzul.com
bot.digitalpointer.id
bot.eikju.photography
bot.eymaleggingsg.com
bot.gamesimples.store
bot.incusservices.com
bot.jogomoderno.store
bot.mejoralasalud.fun
bot.meuesocial.com.br
bot.mycompany.reviews
bot.outstandbrand.com
bot.ramonmatos.com.br
bot.sharemyreview.net
bot.synapsegameia.com
bot.truongnguyen.live
bots.baptistearno.com
botz.cloudsiteapp.com
cdd.searchcube.com.sg
felipewelington.com.br
form.searchcube.com.sg
go.orodrigoribeiro.com
help.giversforgood.com

@vercel
Copy link

@vercel vercel bot commented on 2307231 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.