Skip to content

Commit

Permalink
Merge pull request #7 from lytics/intermediary/interface/0-main
Browse files Browse the repository at this point in the history
Initial Implementation
  • Loading branch information
mgacy authored Feb 22, 2024
2 parents ac3de91 + 3ef8101 commit 6fa5818
Show file tree
Hide file tree
Showing 67 changed files with 37,095 additions and 749 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{kt,swift}]
indent_size = 4
9 changes: 4 additions & 5 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ runs:
with:
path: |
**/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
yarn install --cwd example --frozen-lockfile
yarn install --frozen-lockfile
run: yarn install --immutable
shell: bash
38 changes: 19 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
name: CI
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -27,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -39,36 +38,36 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepack
run: yarn prepare

build-android:
runs-on: ubuntu-latest
env:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for Android
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-android-
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
Expand All @@ -79,7 +78,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Finalize Android SDK
if: env.turbo_cache_hit != 1
Expand All @@ -88,7 +87,7 @@ jobs:
- name: Cache Gradle
if: env.turbo_cache_hit != 1
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.gradle/wrapper
Expand All @@ -102,27 +101,27 @@ jobs:
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
runs-on: macos-latest
runs-on: macos-14
env:
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Cache turborepo for iOS
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('**/yarn.lock') }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-turborepo-ios-
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
Expand All @@ -131,7 +130,7 @@ jobs:
- name: Cache cocoapods
if: env.turbo_cache_hit != 1
id: cocoapods-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
**/ios/Pods
Expand All @@ -142,7 +141,8 @@ jobs:
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
yarn example pods
cd example/ios
pod install
env:
NO_FLIPPER: 1

Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ buck-out/
android/app/libs
android/keystores/debug.keystore

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Expo
.expo/

Expand All @@ -68,3 +76,5 @@ android/keystores/debug.keystore

# generated by bob
lib/

example/ios/.xcode.env.local
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

874 changes: 874 additions & 0 deletions .yarn/releases/yarn-3.6.1.cjs

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions .yarnrc

This file was deleted.

10 changes: 10 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
nodeLinker: node-modules
nmHoistingLimits: workspaces

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
123 changes: 122 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,125 @@

## Installation

## Usage
Install the SDK:

```sh
yarn add react-native-lytics
```

### Android

Add the following permissions to your `AndroidManifest.xml` file:

```xml
<uses-permission android:name="android.permission.INTERNET" />
```

This permission is required to send events to the Lytics API.

```xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```

This permission is technically optional but highly recommended to allow the library to determine the best time to send events to the API.

### iOS

Install native modules:

```sh
npx pod-install
```

## Configuration

You must initialize the Lytics SDK with your [API token](https://learn.lytics.com/documentation/product/features/account-management/managing-api-tokens) before using it.

```jsx
import { start } from 'react-native-lytics';

start({
apiToken: 'xxxxxx',
...
});
```

## Sending Data

### Identity Events

Tracking identity events provides an interface for updating the current user's properties stored on device as well as emitting an identify event to the downstream collections API.

```jsx
import { identify } from 'react-native-lytics';

identify({ identifiers: { email: 'jdoe@email.com' } });
```

### Consent Events

Consent events provide an interface for configuring and emitting a special event that represents an app users explicit consent. This event does everything a normal event does in addition to providing a special payload for consent details at the discretion of the developer.

```jsx
import { consent } from 'react-native-lytics';

consent({
consent: {
documents: ['terms_aug_2022', 'privacy_may_2022'],
consented: true,
},
});
```

### Track Custom Events

Track custom events provides an interface for configuring and emitting a custom event at the customers discretion throughout their application (e.g. made a purchase or logged in).

```jsx
import { track } from 'react-native-lytics';

track({ name: 'Event_Tap', properties: { event: 'Event_Tap' } });
```

### Screen Events

Screen events provide an interface for configuring and emitting a special event that represents a screen or page view. It should be seen as an extension of the track method.

```jsx
import { screen } from 'react-native-lytics';

screen({
name: 'Event_Detail',
properties: { artistID: 123, eventID: 345 },
});
```

## Advertising ID

### Android

To support collecting the Android Advertising ID, add the following to the application's gradle dependencies:

`implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'`

Additionally, declare a Google Play services normal permission in the manifest file as follows:

`<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>`

After confirming with the user and getting their consent, enable Advertiser ID collection via `Lytics.enableGAID()`.

The user's Android Advertising ID will be sent with each event's identifiers.

Note, the user can disable or change the Advertising ID via the Android system privacy settings.

### iOS

Before collecting the IDFA you must first add a [`NSUserTrackingUsageDescription`](https://developer.apple.com/documentation/bundleresources/information_property_list/nsusertrackingusagedescription) to your app's `Info.plist`. You can then call `requestTrackingAuthorization()` to have iOS request authorization to access the IDFA. Note that the alert will not be displayed if the user has turned off “Allow Apps to Request to Track” in the system privacy settings and that authorization can be revoked at any time.

### Usage

```jsx
import { requestTrackingAuthorization } from 'react-native-lytics';

requestTrackingAuthorization();
```
24 changes: 6 additions & 18 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def isNewArchitectureEnabled() {
apply plugin: "com.android.library"
apply plugin: "kotlin-android"


def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}
Expand All @@ -42,16 +39,12 @@ def supportsNamespace() {
def minor = parsed[1].toInteger()

// Namespace support was added in 7.3.0
if (major == 7 && minor >= 3) {
return true
}

return major >= 8
return (major == 7 && minor >= 3) || major >= 8
}

android {
if (supportsNamespace()) {
namespace "com.sdk"
namespace "com.lytics.react_native"

sourceSets {
main {
Expand All @@ -65,8 +58,9 @@ android {
defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

}

buildTypes {
release {
minifyEnabled false
Expand All @@ -81,7 +75,6 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

}

repositories {
Expand All @@ -97,12 +90,7 @@ dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
// FIXME: specify stable version
implementation 'com.github.lytics:android-sdk:main-SNAPSHOT'
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "Sdk"
codegenJavaPackageName = "com.sdk"
}
}
2 changes: 1 addition & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sdk">
package="com.lytics.react_native">
</manifest>
Loading

0 comments on commit 6fa5818

Please sign in to comment.