Skip to content

Commit

Permalink
Added analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropicalista committed Jul 11, 2024
1 parent fec2d0f commit 1f48e6a
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 8 deletions.
14 changes: 14 additions & 0 deletions build/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-show-annotation-tools",
"default": true
},
"enableTextSelection": {
"type": "boolean",
"source": "attribute",
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-enable-text-selection",
"default": true
},
"measurementId": {
"type": "string",
"source": "attribute",
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-measurement-id",
"default": ""
}
},
"textdomain": "pdf-embed",
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => '76b644e34955602b9326');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'bce412595a36e6da44a6');
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'c6c45ce8d90c7df85524');
<?php return array('dependencies' => array(), 'version' => 'c2b4658dfed3ab76d4fe');
2 changes: 1 addition & 1 deletion build/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pdf-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pdf Embed
* Plugin URI: https://francescopepe.com/
* Description: PDF embedded with official Adobe API.
* Version: 0.4.7
* Version: 0.4.8
* Author: Tropicalista
* Author URI: https://www.francescopepe.com
* License: GPL2
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: tropicalista
Tags: pdf embedder, embed pdf, pdf embed api, pdf block, block
Tested up to: 6.5
Stable tag: 0.4.7
Stable tag: 0.4.8
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Requires at least: 5.6.0
Expand Down Expand Up @@ -78,6 +78,10 @@ Yes you will need a free [Adobe PDF Embed API](https://developer.adobe.com/docum

== Changelog ==

= 0.4.8 =
* Added Analytics tracking.
* Added option to disable text selection

= 0.4.7 =
* Fix tracker.

Expand Down
14 changes: 14 additions & 0 deletions src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-show-annotation-tools",
"default": true
},
"enableTextSelection": {
"type": "boolean",
"source": "attribute",
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-enable-text-selection",
"default": true
},
"measurementId": {
"type": "string",
"source": "attribute",
"selector": "div.wp-block-tropicalista-pdfembed",
"attribute": "data-measurement-id",
"default": ""
}
},
"textdomain": "pdf-embed",
Expand Down
4 changes: 4 additions & 0 deletions src/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default function save( { attributes, className } ) {
showAnnotationTools,
enableFormFilling,
dockPageControls,
measurementId,
enableTextSelection,
} = attributes;

return (
Expand All @@ -39,6 +41,8 @@ export default function save( { attributes, className } ) {
data-default-view-mode={ defaultViewMode || undefined }
data-show-annotation-tools={ showAnnotationTools || undefined }
data-enable-form-filling={ enableFormFilling || undefined }
data-measurement-id={ measurementId || undefined }
data-enable-text-selection={ enableTextSelection || undefined }
></div>
);
}
24 changes: 24 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
PanelBody,
SelectControl,
ToggleControl,
TextControl,
BaseControl,
} from '@wordpress/components';
import { HeightControl } from '@wordpress/block-editor';
Expand All @@ -27,6 +28,8 @@ export default function Settings( props ) {
showBookmarks,
showThumbnails,
dockPageControls,
enableTextSelection,
measurementId,
} = attributes;

const embedModeHelp = {
Expand Down Expand Up @@ -249,6 +252,27 @@ export default function Settings( props ) {
/>
</BaseControl>
) }

<ToggleControl
label={ __( 'Enable Text Selection', 'pdf-embed' ) }
checked={ enableTextSelection }
onChange={ ( val ) =>
setAttributes( { enableTextSelection: val } )
}
help={ __( 'Enable text selection in PDF.', 'pdf-embed' ) }
/>

<TextControl
label={ __( 'Google Analytics', 'pdf-embed' ) }
value={ measurementId }
onChange={ ( val ) =>
setAttributes( { measurementId: val } )
}
help={ __(
'Add your measurement id to track pdf event in Google Analytics.',
'pdf-embed'
) }
/>
</PanelBody>
</Fragment>
);
Expand Down
15 changes: 13 additions & 2 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ document.addEventListener( 'adobe_dc_view_sdk.ready', function () {
clientId: embedConfig.clientId,
divId: elms[ i ].id,
locale: userLang,
measurementId: embedConfig.measurementId,
} );
adobeDCView.previewFile(
const previewFilePromise = adobeDCView.previewFile(
{
content: {
location: {
Expand All @@ -40,6 +41,16 @@ document.addEventListener( 'adobe_dc_view_sdk.ready', function () {
enableFormFilling: Boolean( embedConfig.enableFormFilling ),
}
);
previewFilePromise.then( ( adobeViewer ) => {
adobeViewer.getAPIs().then( ( apis ) => {
apis.enableTextSelection(
Boolean( embedConfig.enableTextSelection )
);
if ( embedConfig.goTo ) {
apis.gotoLocation( embedConfig.goTo );
}
} );
} );
}

const buttons = document.querySelectorAll( '.embedPdf>a, a.embedPdf' );
Expand All @@ -65,7 +76,7 @@ function previewFile( e ) {
}

/* Initialize the AdobeDC View object */
const adobeDCView = new AdobeDC.View( {
const adobeDCView = new window.AdobeDC.View( {
/* Pass your registered client id */
clientId: pdf_embed.apiKey,
} );
Expand Down

0 comments on commit 1f48e6a

Please sign in to comment.