Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jserpapinto committed Aug 14, 2017
0 parents commit 70a449d
Show file tree
Hide file tree
Showing 13 changed files with 946 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DON'T BE A DICK PUBLIC LICENSE

Version 1, December 2009

Copyright (C) 2009 Philip Sturgeon [email protected]

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

DON'T BE A DICK PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

Do whatever you like with the original work, just don't be a dick.

Being a dick includes - but is not limited to - the following instances:

1a. Outright copyright infringement - Don't just copy this and change the name.
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.

If you become rich through modifications, related works/services, or supporting the original work, share the love. Only a dick would make loads off this work and not buy the original works creator(s) a pint.

Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Composer Library Template
=========================

If you are trying to create a new PHP Composer library, whether it will be going to submitted to packagist.org or just in your Github account, this template of files will surely help you make the process a lot easier and faster.

Features
--------

* PSR-4 autoloading compliant structure
* Unit-Testing with PHPUnit
* Comprehensive Guides and tutorial
* Easy to use to any framework or even a plain php file


I encourage that you put more information on this readme file instead of leaving it as is. See [http://www.darwinbiler.com/designing-and-making-the-readme-file-for-your-github-repository/](How to make a README file) for more info.
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "lvengine/analytics",
"description": "Fetch data from GA",
"license": "proprietary",
"authors": [
{
"name": "João Serpa | LVEngine",
"email": "[email protected]"
}
],
"type": "project",
"require": {
"php": ">=5.4",
"google/apiclient": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "5.2.*"
},
"autoload": {
"psr-4": {
"Analytics\\": "src/Analytics/"
}
}
}
17 changes: 17 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require_once __DIR__ . '/vendor/autoload.php';


use \Analytics\Ga;
use \Analytics\Audience;
use \Analytics\Conversion;
use \Analytics\Behavior;

$audience = new Behavior();
$audience->setViewId("137104990");
$audience->setDate("2017-08-01", "2017-08-07");

echo "<pre>";
print_r($audience->internalSearches());
echo "</pre>";
12 changes: 12 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true">
<testsuites>
<testsuite name="Unit Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
56 changes: 56 additions & 0 deletions src/Analytics/aquisition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Analytics;

/**
* Aquisition
* ---
* This Class access and makes available the
* Aquisition requests.
*
* @author [email protected]
*/
class Aquisition extends Ga
{

//
// ─── PUBLIC METHODS ─────────────────────────────────────────────────────────────
//
public function sessionsByChannel()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions'),
'dimensions' => array('channelGrouping')
)
);
}
public function sessionsBySourcesMediums()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions'),
'dimensions' => array('sourceMedium')
)
);
}
public function campaigns()
{
return $this->metricsByDimensions(
array(
'metrics' => array('users', 'newUsers', 'sessions', 'bounceRate', 'avgSessionDuration'),
'dimensions' => array('campaign'),
"sorts" => array(
array(
'fieldName' => 'ga:users',
'orderType' => 'VALUE',
'sortOrder' => 'DESCENDING'
)
),
'page_size' => 21
)
);
}
// ────────────────────────────────────────────────────────────────────────────────

}
65 changes: 65 additions & 0 deletions src/Analytics/audience.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Analytics;

/**
* Audience
* ---
* This Class access and makes available the
* Audience requests.
*
* @author [email protected]
*/
class Audience extends Ga
{

//
// ─── PUBLIC METHODS ─────────────────────────────────────────────────────────────
//
public function sessionsByGender()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions'),
'dimensions' => array('userGender')
)
);
}
public function sessionsByAge()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions'),
'dimensions' => array('userAgeBracket')
)
);
}
public function sessionsByCountry()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions'),
'dimensions' => array('country')
)
);
}
public function sessionsAndUsers()
{
return $this->metricsByDimensions(
array(
'metrics' => array('sessions', 'users'),
'dimensions' => array('date')
)
);
}
public function bounceRate()
{
return $this->metricsByDimensions(
array(
'metrics' => array('bounceRate'),
)
);
}
// ────────────────────────────────────────────────────────────────────────────────

}
72 changes: 72 additions & 0 deletions src/Analytics/behavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Analytics;

/**
* Behavior
* ---
* This Class access and makes available the
* Behavior requests.
*
* @author [email protected]
*/
class Behavior extends Ga
{
//
// ─── PUBLIC METHODS ─────────────────────────────────────────────────────────────
//
public function internalSearches()
{
return $this->metricsByDimensions(
array(
'metrics' => array('searchUniques'),
'dimensions' => array('searchKeyword'),
'sorts' => array(
array(
'fieldName' => 'ga:searchUniques',
'orderType' => 'VALUE',
'sortOrder' => 'DESCENDING'
)
),
"page_size" => 25
)
);
}
public function internalSearchesWithoutResults()
{
return $this->metricsByDimensions(
array(
'metrics' => array('totalEvents', 'uniqueEvents'),
'dimensions' => array('eventLabel'),
'sorts' => array(
array(
'fieldName' => 'ga:totalEvents',
'orderType' => 'VALUE',
'sortOrder' => 'DESCENDING'
)
),
'page_size' => 25,
'filters' => 'ga:eventAction==Sem Resultados'
)
);
}
public function eCommerceEvents()
{
return $this->metricsByDimensions(
array(
'metrics' => array('totalEvents', 'uniqueEvents'),
'dimensions' => array('eventAction'),
'sorts' => array(
array(
'fieldName' => 'ga:totalEvents',
'orderType' => 'VALUE',
'sortOrder' => 'DESCENDING'
)
),
'page_size' => 25,
'filters' => 'ga:eventCategory==eCommerce,ga:eventAction!=Product Impression'
)
);
}
// ────────────────────────────────────────────────────────────────────────────────
}
Loading

0 comments on commit 70a449d

Please sign in to comment.