# Godot Engine

## Godot SDK integration

The DevToDev SDK extends the Godot engine in a modular way and supports the following platforms: **MacOS, iOS, Android.**

### Requirements <a href="#requirements" id="requirements"></a>

* Godot engine 4.0+ ([Source code](https://docs.godotengine.org/en/4.0/contributing/development/compiling/getting_source.html#doc-getting-source))
* [Python 3.6+](https://www.python.org/downloads/macos/).
* [SCons 3.0+](https://scons.org/pages/download.html) build system.
* SDK module source code ([GitHub repository](https://github.com/devtodev-analytics/Godot-sdk/releases/latest))

### The SDK module installation <a href="#the-sdk-module-installation" id="the-sdk-module-installation"></a>

The SDK module is available in [GitHub repository](https://github.com/devtodev-analytics/Godot-sdk/releases/latest). Download the Source code of latest release and copy ***d2d\_analytics*** folder to the ***modules***(`/godot/modules/`) folder of Godot engine source code.

To work in the Godot editor, compile the engine source code and the analytics module:

```shell
scons platform=macos arch=x86_64
scons platform=macos arch=arm64
lipo -create bin/godot.macos.editor.x86_64 bin/godot.macos.editor.arm64 -output bin/godot.macos.editor.universal

cp -r misc/dist/macos_tools.app ./Godot.app
mkdir -p Godot.app/Contents/MacOS
cp bin/godot.macos.editor.universal Godot.app/Contents/MacOS/Godot
cp modules/d2d_analytics/native/macos/libDTDAnalytics.dylib Godot.app/Contents/MacOS/
chmod +x Godot.app/Contents/MacOS/Godot
codesign --force --timestamp --options=runtime --entitlements misc/dist/macos/editor.entitlements -s - Godot.app
```

[Find out more about compiling for MacOS](https://docs.godotengine.org/en/4.0/contributing/development/compiling/compiling_for_macos.html)

### SDK Initialization <a href="#sdk-initialization" id="sdk-initialization"></a>

For initialization, add the following code at the start of your application:

```gdscript
var config = GDDTDAnalyticsConfiguration.new()
config.logLevel = GDDTDLogLevel.Debug
DTDAnalytics.InitializeWithConfig("App ID", config)
```

You can find the `App ID` in the settings of the respective app in devtodev (Settings → SDK → Integration → [Credentials](https://docs.devtodev.com/reports-and-functionality/project-related-reports-and-fuctionality/settings#integration)).&#x20;

For [Cross-platform type projects](https://docs.devtodev.com/getting-started/cross-platform-application) use `App ID + Platform ID` .

`config` – an object instance of `GDDTDAnalyticsConfiguration`, which is used for specifying additional properties during the initialization

| **Parameter**          | **Type**                   | **Description**                                                                                                                                                                                                                                                                                     |
| ---------------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `CurrentLevel`         | Integer                    | The player level at the moment of devtodev SDK initialization. It’s optional but we recommend using it for improving data accuracy.                                                                                                                                                                 |
| `UserId`               | String                     | A custom user ID assigned by the developer. In the case of default calculation by device IDs, the identifier can be used for searching users in devtodev. In case the project uses calculation by user IDs, the parameter is mandatory because it becomes the principal calculation ID in devtodev. |
| `TrackingAvailability` | GDDTDTrackingStatus (enum) | The property allows or disallows devtodev tracking of the user. By default, it is set to `GDDTDTrackingStatus.Enable`. SDK stores the previously assigned value. Pass `GDDTDTrackingStatus.Disable` if the user opted out of tracking in line with GDPR.                                            |
| `LogLevel`             | GDDTDLogLevel (enum)       | The level of logging the SDK activity. The `GDDTDLogLevel.No` value is used by default. For troubleshooting during integration it is recommended to set it to `GDDTDLogLevel.Debug`, and either switch it off `GDDTDLogLevel.No`. Use `GDDTDLogLevel.No` in the release version.                    |

\
Example:

```gdscript
var config = GDDTDAnalyticsConfiguration.new() 
config.logLevel = GDDTDLogLevel.No 
config.trackingStatus = GDDTDTrackingStatus.Enable 
config.currentLevel = 1 
config.userId = "unique_userId" 
DTDAnalytics.InitializeWithConfig("AppID", config)
```

## Project export <a href="#project-export" id="project-export"></a>

### Export for MacOS <a href="#export-for-macos" id="export-for-macos"></a>

Open the Export Template Manager to download and install templates:

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FFLyUdkTlqV9MvCZv46Pd%2Fimage.png?alt=media&#x26;token=7c9162f5-b281-49c5-8618-e3058b79efa1" alt="" width="298"><figcaption></figcaption></figure>

Open a terminal, go to the root directory of the engine source code. Compile a custom template for MacOS (see [Building export templates](https://docs.godotengine.org/en/4.0/contributing/development/compiling/compiling_for_macos.html#building-export-templates) for MacOS), select Debug or Release build and processor architecture. To support both architectures in a single Universal 2 binary, use ***lipo***:

```sh
scons platform=macos target=template_debug arch=x86_64
scons platform=macos target=template_debug arch=arm64
lipo -create bin/godot.macos.template_debug.x86_64 bin/godot.macos.template_debug.arm64 -output bin/godot.macos.template_debug.universal
```

The next step is to prepare a custom template as a ***macos.zip*** archive. Don't forget to add the DTDAnalytics native library, copy `libDTDAnalytics.dylib` to `macos_template.app/Contents/MacOS/`.

```sh
cp -r misc/dist/macos_template.app .
mkdir -p macos_template.app/Contents/MacOS
cp bin/godot.macos.template_debug.universal macos_template.app/Contents/MacOS/godot_macos_debug.universal
cp modules/d2d_analytics/native/macos/libDTDAnalytics.dylib macos_template.app/Contents/MacOS/
chmod +x macos_template.app/Contents/MacOS/godot_*
chmod +x macos_template.app/Contents/MacOS/libDTDAnalytics.dylib
zip -q -9 -r macos.zip macos_template.app
```

Open the Export menu and specify the path to the prepared custom template:

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FkcbSuPPXrtu4tP6hgZZR%2Fimage.png?alt=media&#x26;token=1eee86db-76bf-4879-8886-8be8f93ba61c" alt="" width="563"><figcaption></figcaption></figure>

### Export for iOS <a href="#export-for-ios" id="export-for-ios"></a>

Open the Export Template Manager to download and install templates:

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2Fs3FNtHKuAMgTIP1MLNsJ%2Fimage.png?alt=media&#x26;token=c24fa9d4-6eb0-470f-b950-b00c8c637ce4" alt="" width="298"><figcaption></figcaption></figure>

Open a terminal, go to the root directory of the engine source code. And compile a custom template for iOS (see [Compiling](https://docs.godotengine.org/en/4.0/contributing/development/compiling/compiling_for_ios.html#compiling) for iOS). To work with the iOS simulator, compile the sources with the `ios_simulator=yes` flag. To support both architectures in a single Universal 2 binary, use ***lipo***:

```sh
scons p=ios target=template_debug
scons p=ios target=template_release
scons p=ios target=template_debug ios_simulator=yes arch=x86_64
scons p=ios target=template_debug ios_simulator=yes arch=arm64

cp -r misc/dist/ios_xcode .
cp bin/libgodot.ios.template_debug.arm64.a ios_xcode/libgodot.ios.debug.xcframework/ios-arm64/libgodot.a
lipo -create bin/libgodot.ios.template_debug.arm64.simulator.a bin/libgodot.ios.template_debug.x86_64.simulator.a -output ios_xcode/libgodot.ios.debug.xcframework/ios-arm64_x86_64-simulator/libgodot.a

cp bin/libgodot.ios.template_release.arm64.a ios_xcode/libgodot.ios.release.xcframework/ios-arm64/libgodot.a
lipo -create bin/libgodot.ios.template_debug.arm64.simulator.a bin/libgodot.ios.template_debug.x86_64.simulator.a -output ios_xcode/libgodot.ios.release.xcframework/ios-arm64_x86_64-simulator/libgodot.a
```

The next step is to prepare a custom template as an ***ios.zip*** archive. Don't forget to add the DTDAnalytics native library, copy `DTDAnalytics.xcframework` to `ios_xcode/`.

```sh
cp -r modules/d2d_analytics/native/ios/DTDAnalytics.xcframework ios_xcode/
cd "ios_xcode"
zip -q -r ios.zip ./*
cd ..
cp "ios_xcode/ios.zip" ./
```

In XCode project:

1. Add `DTDAnalytics.xcframework` to the project (with ***Do Not Embed*** specified)

   <figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FxO8gPuIJ9NycHbLJGsJ1%2Fimage.png?alt=media&#x26;token=2b83acb4-c1c6-4075-9ab9-f0c91ce4114c" alt=""><figcaption></figcaption></figure>
2. Create Bridging-Header. To do this, add any swift file to the project (don't delete it later) and select 'Create Bridging Header' in the dialogue box that appears.<br>

   <figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FVcA6lGyc4r2K9ZTv84Ko%2Fimage.png?alt=media&#x26;token=f3fbd157-ed43-4af5-8857-96d2132c043e" alt="" width="375"><figcaption></figcaption></figure>
3. Add frameworks:
   * `AppTrackingTransparency.framework`
   * `AdSupport.framework`

### Export for Android <a href="#export-for-android" id="export-for-android"></a>

Click to install android templates:

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FJ0CbGwQ3JbcSiYt3A2eQ%2Fimage.png?alt=media&#x26;token=c9556a40-26fb-4ee1-aab2-42e59083491d" alt="" width="375"><figcaption></figcaption></figure>

After installing the template, an android folder will appear in your project.

Move the `d2d_analytics/native/androidAnalytics.aar` to the `android/plugins/ folder` in your project. You will also need to create an `Analytics.gdap` file in `android/plugins/` with the following content:

```
[config]

name="Analytics"
binary_type="local"
binary="Analytics.aar"

[dependencies]

remote=[
    "com.google.code.gson:gson:2.8.9", 
    "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2", 
    "com.google.android.gms:play-services-ads-identifier:18.0.1",
    "com.devtodev:android-google:1.0.0"
    // Optional (recommended)
    "com.android.installreferrer:installreferrer:2.2"
    ]

custom_maven_repos=["https://repo.maven.apache.org/maven2/"]
```

Next, Analytics should appear in the Plugins section, check it out:

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2F3ONNaP4Tlrr4XrohY4Vw%2Fimage.png?alt=media&#x26;token=9c982182-1174-4261-85c5-1f0144f0c973" alt="" width="563"><figcaption></figcaption></figure>

The next step is to compile the Godot engine for Android (see [Android compilation](https://docs.godotengine.org/en/4.0/contributing/development/compiling/compiling_for_android.html)), choose debug or release build, and select the processor architecture.

```sh
// Example. For debug on arm64v8 architecture use:
scons platform=android target=template_debug arch=arm64v8
//for release:
scons platform=android target=template_release arch=arm64v8
```

After successful compilation execute the following commands:

```sh
// Example. For debug on arm64v8 architecture use:
scons platform=android target=template_debug arch=arm64v8
//for release:
scons platform=android target=template_release arch=arm64v8
```

In the next step in `godot-4.0-stable/bin` you will see `godot-lib.template_debug.aar` or

`godot-lib.template_relaese.aar`.

You need to copy and replace this file to the previously installed template in your project at the path:

* `appName/android/build/libs/debug` - for debugging
* `appName/android/build/libs/release` - for release

After these steps, you are ready to export your Android app.

<figure><img src="https://2105883905-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LnGcP_ZeRJ1ipj9O8dF%2Fuploads%2FuRJTDxdpOrumIpWmXEwk%2Fimage.png?alt=media&#x26;token=1494c22f-c57e-4660-8c52-ca4586bcdde7" alt="" width="563"><figcaption></figcaption></figure>

Make sure that `Use Gradle Build` (in the Gradle Build section), `Analytics` (in the Plugins section) and the previously compiled `Architecture` (in the Architectures section) are selected.
