/
gosquared-official.php
96 lines (80 loc) · 3.5 KB
/
gosquared-official.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @package GoSquaredOfficial
*/
/*
Plugin Name: GoSquared - Marketing Automation, CRM, Analytics and Live Chat for WordPress
Plugin URI: https://github.com/gosquared/gosquared-official-wordpress
Description: This is the official GoSquared Plugin for analytics, live chat and lead capture.
Version: 1.3.0
Author: GoSquared
License: GPLv2 or later
Text Domain: GoSquared-Offical
*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( ! defined ( 'ABSPATH' ) ) {
die;
}
class GSOF_GoSquaredOfficial
{
function __construct() {
add_action( 'plugins_loaded', array( $this, 'GSOF_load_tracker' ) );
}
function GSOF_load_tracker() {
require_once 'includes/gosquared-official-options.php';
require_once 'includes/gosquared-official-gravity-forms-integration.php';
$this->gsOfficialSettings = new GSOF_GoSquaredOptionsPage;
add_action( 'wp_head', array( $this, 'GSOF_gs_snippet' ) );
$this->project_token = $this->gsOfficialSettings->GSOF_get( 'GSOF_gosquared_site_token' );
if( 1 == absint( $this->gsOfficialSettings->GSOF_get( 'GSOF_gosquared_identify' ) ) ) {
add_action( 'gosquared_identify_snippet', array( $this, 'GSOF_add_identify' ) );
}
if( 1 == absint( $this->gsOfficialSettings->GSOF_get( 'GSOF_gosquared_gravity_forms' ) ) ) {
$this->gsGfint = new GSOF_GoSquaredGFIntegration($this->project_token);
}
}
function GSOF_gs_snippet() {
echo "<script>";
echo "!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(";
echo "arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];";
echo "d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';q.parentNode.";
echo "insertBefore(d,q)}(window,document,'script','_gs');";
echo "_gs('" . $this->gsOfficialSettings->GSOF_get( 'GSOF_gosquared_site_token' ) . "');";
do_action( 'gosquared_identify_snippet' );
echo "</script>";
}
public function GSOF_add_identify() {
$current_user=wp_get_current_user();
$properties = array();
$this->properties['custom']=array();
$this->properties['email'] = $current_user->user_email;
$this->properties['first_name']= $current_user->user_firstname;
$this->properties['last_name'] = $current_user->user_lastname;
$this->properties['custom']['username']= $current_user->user_login;
if ($this->properties['email'] && $this->properties['email'] !== null && $this->properties['email'] !== '') {
echo "_gs('identify'," . json_encode($this->properties) . ")";
}
}
}
if ( class_exists( 'GSOF_GoSquaredOfficial' ) ) {
$gsOfficial = new GSOF_GoSquaredOfficial();
}
function GSOF_plugin_action_links( $links ) {
$links = array_merge( array(
'<a href="' . esc_url( admin_url( '/options-general.php?page=gosquared-official-plugin.php' ) ) . '">' . __( 'Settings', 'textdomain' ) . '</a>'
), $links );
return $links;
}
add_action( 'plugin_action_links_gosquared-official-wordpress/gosquared-official.php', 'GSOF_plugin_action_links' );