-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8ee6d97
Showing
9 changed files
with
361 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.log | ||
.htaccess | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 TB | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
## Crash Forwarding - Sentry.io to Adjust.com | ||
|
||
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Send%20sentry%20crash%20events%20to%20your%20analytics&url=&hashtags=crash,analytics,events,mobile) [![Language](http://img.shields.io/badge/language-php-brightgreen.svg?style=flat)](https://php.net) | ||
## Overview ## | ||
|
||
PHP Crash Parser from Sentry to Mobile analytics, export data to Adjust.com | ||
|
||
## Table of contents | ||
|
||
* [Working with the Parser](#start) | ||
* [Prerequisite](#prerequisite) | ||
* [Sentry Tags](#sentry-tags) | ||
* [Activate WebHooks](#sentry-hooks) | ||
* [Server Set Up](#set-up) | ||
* [Logging your results](#logs) | ||
* [Licence](#licence) | ||
|
||
## <a id="start"></a>Working with the Parser ## | ||
|
||
### <a id="prerequisite"></a>Prerequisite ### | ||
|
||
Before getting started with the set up make sure you run SaaS or On-Premise Sentry and Implement Sentry SDK with Tags. | ||
|
||
----- | ||
|
||
#### <a id="sentry-tags"></a>Sentry Tags #### | ||
|
||
Integrate Sentry SDK and enrich your device level data with device_id's such as `idfa` / `idfv` or `user_id`. See details on Tags [here][sentry-tags]. | ||
|
||
Swift: | ||
```swift | ||
import Sentry | ||
|
||
SentrySDK.configureScope { scope in | ||
scope.setTag(value:sentry_idfa, key: "idfa") | ||
scope.setTag(value:sentry_idfv, key: "idfv") | ||
} | ||
``` | ||
|
||
Objective-C: | ||
```objc | ||
@import Sentry; | ||
|
||
[SentrySDK configureScope:^(SentryScope * scope) { | ||
[scope setTagValue:sentry_idfa forKey:@"idfa" ]; | ||
[scope setTagValue:sentry_idfv forKey:@"idfv"]; | ||
}]; | ||
``` | ||
--- | ||
#### <a id="sentry-hooks"></a>Activate WebHooks #### | ||
Activate your sentry WebHooks in Sentry Interface or by the link : | ||
https://`{{url}}`/settings/`{{company_slug}}`/projects/`{{project_slug}}`/plugins/webhooks/ | ||
<img src="https://tabee.app/img/sentry_webhooks.png" width="650"> | ||
Learn more on details about Sentry hooks format [here][sentry-hooks]. | ||
--- | ||
### <a id="set-up"></a>Server Set Up ### | ||
Clone repository to PHP enabled server, e.g. to subfolder of your landing page and make sure it is available on web. | ||
``` | ||
$ git clone https://github.com/tabeeapp/sentry-webhook-fw-analytics.git | ||
``` | ||
Copy `modules/adjust-config-temp.php` and set up your credentials in newly created config. | ||
``` | ||
$ cd modules | ||
$ cp adjust-config-temp.php adjust-config.php | ||
``` | ||
You are all set now. | ||
--- | ||
#### <a id="logs"></a>Logging your results #### | ||
To disable logs just set it so in `adjust-config.php` | ||
``` | ||
define( 'LOG', false ); | ||
``` | ||
--- | ||
[Logs]: logs/ | ||
[sentry-tags]: https://docs.sentry.io/platforms/apple/guides/ios/enriching-events/tags/ | ||
[sentry-hooks]: https://docs.sentry.io/product/integrations/integration-platform/webhooks/#issue-alerts | ||
## <a id="licence"></a>Licence and Copyright ## | ||
The php module is licensed under the MIT License. | ||
Tabee Networking Limited (c) 2020 All Rights Reserved | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
[![Analytics](https://ga-beacon.appspot.com/UA-125243602-3/sentry-crash/README.md)](https://github.com/igrigorik/ga-beacon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* CORS HEADERS (Comment or remove lines if you don't need CORS) */ | ||
header( 'Access-Control-Allow-Origin: *' ); | ||
header( 'Access-Control-Allow-Headers: Content-Type' ); | ||
|
||
/* MODULES */ | ||
require_once __DIR__ . '/modules/request.php'; | ||
require_once __DIR__ . '/modules/log.php'; | ||
|
||
/* | ||
------------- | ||
LOGIC | ||
------------- | ||
*/ | ||
|
||
$uniq = uniqid(); | ||
|
||
wlog( '------------------ START REQUEST ' . $uniq, '', false ); | ||
|
||
/* Get post data */ | ||
$body = json_decode( file_get_contents( 'php://input' ) ); | ||
wlog( 'DATA RECEIVED', $body ); | ||
|
||
if ( empty( (array)$body ) ) { | ||
// Put to the 'test.json' your testing data | ||
// $body = json_decode( file_get_contents( __DIR__ . '/test.json' ) ); | ||
wlog( '------------------ END REQUEST WITH NO BODY ' . $uniq, "\r\n\r\n", false ); | ||
die( '{"status":"error","message":"406 Not Acceptable"}' ); | ||
} | ||
|
||
//Get params from body | ||
$params = extract_params( $body ); | ||
wlog( 'EXTRACTED PARAMS', $params ); | ||
|
||
//Make request URL | ||
$request = generate_request( REQUEST_URL, $params ); | ||
wlog( 'GENERATED REQUEST', $request, false ); | ||
// $request = generate_request( DEBUG_REQUEST_URL, $params ); | ||
|
||
//Make a request | ||
$result = make_request( $request ); | ||
wlog( 'API ANSWER', $result, false ); | ||
echo $result; | ||
|
||
wlog( '------------------ END REQUEST ' . $uniq, "\r\n\r\n", false ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
define( 'LOG', true ); | ||
define( 'REQUEST_URL', 'https://s2s.adjust.com/event' ); | ||
define( 'AUTH_HEADER', 'Authorization: Bearer TOKEN' ); | ||
|
||
/* DEBUG_URL CONFIG */ | ||
// see debug results https://requestbin.com/r/enq9yusclzqt | ||
define( 'DEBUG_REQUEST_URL', 'https://enq9yusclzqt.x.pipedream.net/event' ); | ||
|
||
function config () { | ||
global $config; | ||
return $config; | ||
} | ||
|
||
$config = (object)[ | ||
|
||
'include_tags' => | ||
[ | ||
'browser', 'browser.name', 'handled', 'idfa', 'idfv', | ||
'app.device', 'device', 'device.family', 'dist', 'handled', | ||
'level', 'mechanism', 'os', 'os.name', 'os.rooted', 'release', | ||
'transaction', 'push_token', 'user_id', 'sentry:user' | ||
], | ||
|
||
'include_user' => | ||
[ 'ip_address', 'id' ], | ||
|
||
'clean_keys' => | ||
[ 'user_id', 'transaction', 'sentry:user' ], | ||
|
||
'default_params' => | ||
[ | ||
'event_token' => 'adjust_event_token', | ||
'app_token' => 'adjust_app_token', | ||
's2s' => 1 | ||
] | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
function extract_params ( $data ) { | ||
$params = array_merge( config()->default_params ); | ||
|
||
extract_tags( $params, $data->event->tags ); | ||
extract_user( $params, $data->event->user ); | ||
modify_params( $params ); | ||
clean( $params ); | ||
|
||
return $params; | ||
} | ||
|
||
function extract_tags ( &$params, $tags ) { | ||
foreach ( $tags as $tag ) { | ||
list( $key, $value ) = $tag; | ||
|
||
if ( in_array( $key, config()->include_tags ) ) { | ||
$params[$key] = urlencode( $value ); | ||
} | ||
} | ||
} | ||
|
||
function extract_user( &$params, $user ) { | ||
foreach ( $user as $key => $value ) { | ||
if ( in_array( $key, config()->include_user ) ) { | ||
$params[$key] = urlencode( $value ); | ||
} | ||
} | ||
} | ||
|
||
function modify_params( &$params ) { | ||
$params['sentry_user'] = explode( ':', $params['sentry:user'] )[1]; | ||
|
||
$params['callback_params'] = [ | ||
'user_id' => $params['user_id'], | ||
]; | ||
|
||
$params['partner_params'] = [ | ||
'push_token' => $params['push_token'], | ||
]; | ||
} | ||
|
||
function clean ( &$params ) { | ||
foreach ( config()->clean_keys as $key ) { | ||
unset( $params[$key] ); | ||
} | ||
|
||
foreach ( $params as $key => $value ) { | ||
if ( empty( $value ) ) { | ||
unset( $params[$key] ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* INCLUDE CONFIG */ | ||
require_once __DIR__ . '/adjust-config.php'; | ||
require_once __DIR__ . '/adjust-params.php'; | ||
|
||
function prep_url ( $url ) { | ||
$res= $url; | ||
|
||
if ( substr( $res, -1 ) !== '/' ) { | ||
$res .= '/'; | ||
} | ||
|
||
$res .= '?'; | ||
|
||
return $res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/adjust-config.php'; | ||
|
||
function wlog ( $action, $raw, $convert = true ) { | ||
if ( !LOG ) return; | ||
|
||
$filename = date( 'Y-m-d' ) . '.log'; | ||
$filepath = __DIR__ . '/../logs/' . $filename; | ||
$time = date( 'H:i:s' ); | ||
$data = $convert ? json_encode( $raw ) : $raw; | ||
|
||
$info = [ IP(), $_SERVER['HTTP_REFERER'], $_SERVER['REQUEST_METHOD'] ]; | ||
|
||
$fp = fopen( $filepath, 'a' ); | ||
|
||
fwrite( $fp, $time . ' | ' . $action . ' [' . implode( ', ', $info ) . ']: ' ); | ||
( $convert && !empty( $raw ) ) && ( fwrite( $fp, "\r\n" ) ); | ||
fwrite( $fp, $data ); | ||
fwrite( $fp, "\r\n" ); | ||
|
||
fclose( $fp ); | ||
} | ||
|
||
function IP () { | ||
if ( !empty($_SERVER['HTTP_CLIENT_IP'] ) ) { | ||
return $_SERVER['HTTP_CLIENT_IP']; | ||
} | ||
|
||
if ( !empty($_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { | ||
return $_SERVER['HTTP_X_FORWARDED_FOR']; | ||
} | ||
|
||
return $_SERVER['REMOTE_ADDR']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/adjust-config.php'; | ||
require_once __DIR__ . '/adjust-utils.php'; | ||
|
||
function make_request ( $req ) { | ||
$ch = curl_init(); | ||
|
||
curl_setopt( $ch, CURLOPT_URL, $req ); | ||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); | ||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [ AUTH_HEADER ] ); | ||
|
||
$output = curl_exec( $ch ); | ||
$error = curl_error( $ch ); | ||
$errno = curl_errno( $ch ); | ||
|
||
curl_close( $ch ); | ||
|
||
return $output; | ||
} | ||
|
||
function generate_request ( $url, $params ) { | ||
$res = prep_url( $url ); | ||
$p = ''; | ||
|
||
foreach ( $params as $key => $value ) { | ||
$val = $value; | ||
|
||
if ( is_array( $value ) ) { | ||
$val = json_encode( $value ); | ||
} | ||
|
||
$p .= $key . '=' .$val . '&'; | ||
} | ||
|
||
return substr( $res . $p, 0, -1 ); | ||
} |