YaWK  24.1
Yet another WebKit
YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics Class Reference

Embed Google Analytics on your page. More...

+ Inheritance diagram for YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics:

Public Member Functions

 __construct ($db)
 Load all widget settings from database and fill object. More...
 
 embed ()
 
 init ()
 Init and embed Google Analytics. More...
 
 printObject ()
 Print all object data. More...
 
- Public Member Functions inherited from YAWK\widget
 getHeading ($heading, $subtext)
 Get widget heading and subtext, return headline. More...
 
 getWidgetSettingsArray ($db)
 Get widget settings and return it as array. More...
 

Public Attributes

 $gaTrackingCode = ''
 
 $gaTrackingID = ''
 
 $widget = ''
 
- Public Attributes inherited from YAWK\widget
 $data
 
 $date_publish
 
 $date_unpublish
 
 $folder
 
 $id
 
 $marginBottom
 
 $marginTop
 
 $name
 
 $pageID
 
 $position
 
 $published
 
 $sort
 
 $widgetTitle
 
 $widgetType
 

Additional Inherited Members

- Static Public Member Functions inherited from YAWK\widget
static getAllSettingsIntoArray ($db, $widgetID)
 Returns an array with all widget settings data. More...
 
static getAllWidgetTypes ($db)
 Return all widget types as associative array. More...
 
static getCurrentWidgetPath ($db)
 return current widget path More...
 
static getFacebookLikeBox ()
 return the facebook likebox widget More...
 
static getLoginBox ()
 return the user login box widget More...
 
static loadWidgetsOfPage ($db, $page)
 Returns an array of all widgets that are linked with given page->id. More...
 

Detailed Description

Embed Google Analytics on your page.

Google Analytics Widget - Embed Google Analytics on your page

If you need to track your users with google analytics, you can use this widget. It requires a tracking ID and allows a few settings. In order to work properly, it is required to embed this widget on 'all pages' in any position that is not used by anything else. A recommended position would be debug or any other empty position.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 17 of file googleAnalytics.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::__construct (   $db)

Load all widget settings from database and fill object.

Parameters
object$dbDatabase Object

Load all widget settings on object init.

Definition at line 31 of file googleAnalytics.php.

33  {
34  // load this widget settings from db
35  $this->widget = new \YAWK\widget();
36  $settings = $this->widget->getWidgetSettingsArray($db);
37  foreach ($settings as $property => $value) {
38  $this->$property = $value;
39  $this->gaTrackingID = $this->gaTrackingCode;
40  }
if(isset($_POST['save'])) $settings
$value

References $db, YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics\$gaTrackingCode, $settings, $value, and YAWK\widget\getWidgetSettingsArray().

Member Function Documentation

◆ embed()

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::embed ( )

Definition at line 62 of file googleAnalytics.php.

64  {
65  if (isset($this->gaTrackingID)
66  && (!empty($this->gaTrackingID)))
67  {
68  // make sure that the string contains no html
69  $this->gaTrackingID = strip_tags($this->gaTrackingID);
70 
71  // tracking code seems to be valid -
72  // embed Google Analytics
73  echo'<!-- google analytics -->
74 <!-- Global site tag (gtag.js) - Google Analytics -->
75 <script async src="https://www.googletagmanager.com/gtag/js?id='.$this->gaTrackingID.'"></script>
76 <script>
77  window.dataLayer = window.dataLayer || [];
78  function gtag(){dataLayer.push(arguments);}
79  gtag(\'js\', new Date());
80  gtag(\'config\', \''.$this->gaTrackingCode.'\');
81 </script>';
82  }
83  else
84  { // tracking code not set, empty or wrong data type
85  echo "Google Analytics could not be loaded - tracking code not set, empty or wrong data type.";
86  }

Referenced by YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics\init().

◆ init()

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::init ( )

Init and embed Google Analytics.

Embed Google Analytics

Definition at line 57 of file googleAnalytics.php.

59  { // embed GoogleAnalytics
60  $this->embed();

References YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics\embed().

◆ printObject()

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::printObject ( )

Print all object data.

(for development and testing purpose)

Reimplemented from YAWK\widget.

Definition at line 46 of file googleAnalytics.php.

48  { // output data to screen
49  echo "<pre>";
50  print_r($this);
51  echo "</pre>";

Member Data Documentation

◆ $gaTrackingCode

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::$gaTrackingCode = ''
Parameters
stringTracking Code

Definition at line 24 of file googleAnalytics.php.

Referenced by YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics\__construct().

◆ $gaTrackingID

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::$gaTrackingID = ''
Parameters
stringTracking ID

Definition at line 22 of file googleAnalytics.php.

◆ $widget

YAWK\WIDGETS\GOOGLE\ANALYTICS\googleAnalytics::$widget = ''
Parameters
objectglobal widget object data

Definition at line 20 of file googleAnalytics.php.


The documentation for this class was generated from the following file: