Skip to content

Commit

Permalink
Merge pull request #80 from DripEmail/eci-1921-set-attributes-on-js-s…
Browse files Browse the repository at this point in the history
…nippet

ECI-1921 Implement Custom Script Type and Attributes in Drip's JS Snippet
  • Loading branch information
diegodrip authored Oct 16, 2023
2 parents 6a3a531 + 225c51d commit 43d6ae9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions devtools_wp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM wordpress:6.2.2-php8.1-apache
FROM wordpress:6.3.1-php8.1-apache

RUN curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o /usr/local/bin/wp && chmod +x /usr/local/bin/wp
RUN apt-get update && apt-get install -y less unzip vim wget vim-tiny net-tools

RUN curl https://downloads.wordpress.org/plugin/woocommerce.7.8.2.zip -o /usr/src/woocommerce.zip && cd /usr/src/wordpress/wp-content/plugins && unzip /usr/src/woocommerce.zip
RUN curl https://downloads.wordpress.org/plugin/woocommerce.8.2.0.zip -o /usr/src/woocommerce.zip && cd /usr/src/wordpress/wp-content/plugins && unzip /usr/src/woocommerce.zip
4 changes: 2 additions & 2 deletions devtools_wp/cypress/integration/OrderInteractions/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Then('I add a widget to my cart', () => {
})

Then("the page includes a Drip JS API call", () => {
cy.get('script[src="http://localhost:3007/wp-content/plugins/drip/src/customer_identify.js?ver=6.2.2"]').should('have.length', 1)
cy.get('script[src="http://localhost:3007/wp-content/plugins/drip/src/customer_identify.js?ver=8.2.0"]').should('have.length', 1)

cy.window().then(function(window) {
expect(window._dcq).to.have.lengthOf(1)
Expand All @@ -38,7 +38,7 @@ Then('I add a widget to my cart', () => {
})

Then("the page does not make Drip JS API call", () => {
cy.get('script[src="http://localhost:3007/wp-content/plugins/drip/src/customer_identify.js?ver=6.2.2"]').should('have.length', 0)
cy.get('script[src="http://localhost:3007/wp-content/plugins/drip/src/customer_identify.js?ver=8.2.0"]').should('have.length', 0)

cy.window().then(function(window) {
expect(Object.keys(window)).to.not.include('_dcq')
Expand Down
2 changes: 1 addition & 1 deletion devtools_wp/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ npm --version
```bash
$ npm install
```
- Spin up Docker and Magento, run setup.sh in the devtools_m1 directory
- Spin up Docker and WooCommerce, run setup.sh in the devtools_wp directory
```aidl
./setup.sh
```
Expand Down
4 changes: 2 additions & 2 deletions drip.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
Plugin Name: Drip for WooCommerce
Plugin URI: https://github.com/DripEmail/drip-woocommerce
Description: A WordPress plugin to connect to Drip's WooCommerce integration
Version: 1.1.6
Version: 1.1.7
Author: Drip
Author URI: https://www.drip.com/
License: GPLv2
WC requires at least: 3.0
WC tested up to: 7.8.2
WC tested up to: 8.2.0
*/

defined( 'ABSPATH' ) || die( 'Executing outside of the WordPress context.' );
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: getdrip
Tags: ecommerce, emailmarketing, marketingautomation, emailmarketingautomation, woocommerce, drip
Requires at least: 4.6
Tested up to: 6.2.2
Stable tag: 1.1.6
Tested up to: 6.3.1
Stable tag: 1.1.7
Requires PHP: 5.6
License: GPLv2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -74,6 +74,10 @@ The philosophy behind this plugin is to do as little as possible in it, and as m

* Your change here!

= 1.1.7 =

* Implement `drip_set_snippet_script_type` and `drip_set_snippet_script_additional_attributes` filters to add custom attributes in Drip's JS Snippet

= 1.1.6 =

* Use a more robust method for detecting product view events
Expand Down
14 changes: 13 additions & 1 deletion src/snippet.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

defined( 'ABSPATH' ) || die( 'Executing outside of the WordPress context.' );

$script_type = apply_filters('drip_set_snippet_script_type', 'text/javascript');
$script_additional_attributes = apply_filters('drip_set_snippet_script_additional_attributes', array());
?>

<!-- Drip Code -->
Expand All @@ -17,8 +19,18 @@

(function() {
var dc = document.createElement('script');
dc.type = 'text/javascript'; dc.async = true;
dc.type = '<?php echo esc_js( $script_type ); ?>';
dc.async = true;
dc.src = '//tag.getdrip.com/<?php echo esc_js( $account_id ); ?>.js';
<?php
if(is_array($script_additional_attributes)) {
foreach($script_additional_attributes as $attname => $attval) {
?>
dc.setAttribute("<?php echo esc_js( $attname ); ?>", "<?php echo esc_js( $attval ); ?>");
<?php
}
}
?>
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(dc, s);
})();
Expand Down

0 comments on commit 43d6ae9

Please sign in to comment.